Creating a Form Label Element - laravel

How to create form label element in laravel.
I want to convert below html
<label class="control-label">Status <span class="required">*</span></label>
I used
{!! Form::label('status', 'Status <span class="required">*</span>', array('class' => 'control-label')) !!}
But the output is
Status <span class="required">*</span>
The question is how to render HTML in it, Or is there a way?

You can't - Laravel Collective's Form::label function runs it through htmlspecialchars.
That said, Form::label is just generating HTML. You're fine using raw HTML for this - just add a for="status" to link it up to its form field.
<label class="control-label" for="status">Status <span class="required">*</span></label>
You could, I suppose, run the generated label through htmlspecialchars_decode, but I think that's uglier and confusing for someone else reading your code.
{!! htmlspecialchars_decode(Form::label('status', 'Status <span class="required">*</span>', array('class' => 'control-label'))) !!}

Related

How to set errorPlacement after form-group in Yii2

How can I set errorPlacement in Yii2 activeform or using kartik active form just after form-group?
Below are code for view file.
<div class="col-sm-6">
<div class="form-group field-signupform-value1 required">
<label class="control-label" for="signupform-value1">value1 Name</label>
<input type="text" id="signupform-value1" class="form-control" name="SignupForm[value1]" placeholder="value1 Name" aria-required="true">
<p class="help-block help-block-error"></p>
</div>
</div>
I want html code as below. should auto add after .
<div class="col-sm-6">
<div class="form-group field-signupform-value1 required">
<label class="control-label" for="signupform-value1">value1 Name</label>
<input type="text" id="signupform-value1" class="form-control" name="SignupForm[value1]" placeholder="value1 Name" aria-required="true">
</div>
<p class="help-block help-block-error"></p>
</div>
Looking at your inputs, it is not needed to change the replacement of the error message, though if you want to play with the input template properties, you can refer the following
<?php $form = ActiveForm::begin([
'fieldConfig'=>['template'=>'<div style="border:solid 1px black;padding-bottom:15px">{label}{input}{hint}</div>{error}']
]); ?>
in the above template properties, you can change the placement of error template or event add some HTML inside it, hope it will help you.
Edit:
I have added inline css to div, you can put your css class which is applying outer border.
I achieved by below code. Thank for kind suggestion.
<?php
$form = ActiveForm::begin([
'fieldConfig'=>['template'=>' <div class="custom">
{label}{input}
</div>
{error}',
'inputOptions' => [
'placeholder' => 'Username ...',
'class'=>'form-control',
]]
]); ?>
and given css to "custom" class for border-box
You can use another hidden input like this:
$form->field($model, "your_field")->hiddenInput([
'class' => 'hidden_input_val'
])->label(false) // (for validation messages)
To display error in HTML:
<?=Html::error($model, 'your_field', ['class' => 'help-block']) ?>
Then you just have to hide this hidden input's .help-block with css

Laravel 5.2 mime type validation not working

I am working with the Laravel validation with mime type for image validation. But mime type validation is not validating images.
Here is the validation code
$this->validate($request, [
'image' => 'required|mimes:jpeg,png,jpg,gif,svg',
]);
This is validation script, and here is submission form details.
<div class="form-group">
<div class=" col-sm-12">
{!! Form::file('image', ['class' => 'form-control']) !!}
#if ($errors->has('image')) <span class="help-block">{{ $errors->first('image') }}</span> #endif
</div> </div>
Required validation working well, but when I tying to use mime validation it is not working. Please tell me where I am going wrong.
use this line I think it will be work
'mimetypes:image/jpeg,image/png,image/jpg,image/gif,image/svg'

Bootstrap classes for laravel 5 form submit button

Below is the part of input field and submit button.
I want to increase the width of submit button as the input field using bootstrap.
Here is my code.
<div class="form-group col-md-6">
{!! Form::label('Event Photo') !!}
</div>
<div class="form-group col-md-6">
<input type='file' name='photo' id ='photo' class ='form-control'/>
</div>
<div class="form-group col-md-12">
{!! Form::submit('Add', array('class'=>'btn btn-primary')) !!}
</div>
But the button size can't get increased like that. Where am I wrong? How should I solve that?
The array() part of your form allows you to pass in any other parameters that you want.
Just as you are using it to define the class, you can use it to define the style:
<div class="form-group col-md-12">
{!! Form::submit('Add', array('class'=>'btn btn-primary', 'style' => 'width:50px;)) !!}
</div>
Just change 50px to whatever width you want to use.
Adding the class btn-lg will work.
You can find that in the documentation

Laravel 5.0 paginate jump to page section

I'm using Laravel 5.0 and paginate along with the render() function in my view. Rather than go back to the top of the screen after I select the next page I want it to jump to #msgs.
Here is some of my code:
<h1 class="centered" id="msgs">Announcements</h1>
#foreach($messages->getCollection()->all() as $message)
<div class="row">
<div class="row">
<div class="col-sm-9">
<h3>{{$message->title}}</h3>
</div>
<div class="col-sm-3">
<h4>From: {{$message->author_name}}</h4>
</div>
</div>
<div class="row">
<p>{{$message->text}}</p>
</div>
</div>
<hr class="featurette-divider">
#endforeach
<div class="centered">
{!! $messages->render() !!}
</div>
I'm still getting a grasp on the flow of things in laravel so I'm not really sure what to do. I tried to use append->('#msgs') but realized that its appending an array in the parameters, not appending a path to the url. I there a simple way to achieve this without overriding anything?
You might want to use fragment() method:
{!! $messages->fragment('msgs')->render() !!}
Here is the link to the documentation: Pagination - Laravel

Laravel 5, Forms, TokenMismatchException in VerifyCsrfToken.php line 46

I keep getting the "TokenMismatchException in VerifyCsrfToken.php line 46" error when submitting forms.
This is one of the forms:
{!! Form::model($product, array('url' => 'product/'.$product->id, 'class' => 'form', 'method' => 'PATCH')) !!}
<div class="form-group">
{!! Form::textarea('note', $product->note,
array('class'=>'form-control', 'id'=>'product-note', 'placeholder'=>Lang::get('customtranslation.form_placeholder_note'), 'rows'=>3)) !!}
<br />
<span class="btn btn-link" id="remove-note" role="button"><i class="fa fa-times"></i> {{ Lang::get('customtranslation.button_txt_reset_note') }}</span>
</div>
<div class="form-group">
{!! Form::submit(Lang::get('customtranslation.button_txt_finish_edit_product'), array('class'=>'btn btn-success')) !!}
</div>
<div class="form-group">
<!-- Custom tags -->
{!! Form::label('additional-tags', Lang::get('customtranslation.form_edit_label_additional_tags')) !!}
{!! Form::text('additional-tags','', array('id'=>'additional-tags', 'data-role'=>'tagsinput')) !!}
</div>
{!! Form::close() !!}
The input element with name "_token" gets generated and set as expected.
The strange thing is that this occurs only in Internet Explorer (IE11). Chrome and FF make a submit without any problems.
Does anyone else have this problem and a possible solution?
Internet explorer rejects sessions from domains with an underscore it. This is a known issue.
Please see here: Issue with Session and Cookie in Internet Explorer for websites containing underscore
And also:
http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx
Probably you have not set the _token parameter in your request to the server or you have put it in somewhere incorrect.

Resources