I have 2 email fields and I am using
{{ Form::text('email[]', Input::old('email'),array('class' => 'large-2', 'placeholder' => 'email address','id'=>'email')) }}`
if I use [] to get multiple values for same variable, it is giving error in view page if posted back some data. for example if some fields are mandatory and if user fail to fill those, page will be redirected to same view page from where it was launched.
In such cases it is showing error.
How to fix this issue?
One text field can contain only one data. So, you need another text field to achieve that. if you don't want to show the multiple emails, you can use hidden fields.
{{ Form::hidden('email[]', Input::old('email1'))
{{ Form::hidden('email[]', Input::old('email2'))
Or you can use select. Laravel allow array data if use select field.
For example:
{{ Form::select('size', array('L' => 'Large', 'S' => 'Small')) }}
http://laravel.com/docs/html#drop-down-lists
Related
So I have this code to display one radio button option in a ChoiceType field.
{{ form_widget(form.persontype[0], {"attr":{"id":"student"}}) }}
based on reading the net (mostly discussions here in stackoverflow), it should theoretically change the ID of the radio button. BUT it's not working. Any ideas on how to get it work?
This is my Form builder code in relation to the ChoiceType field.
->add(
"persontype"
, "choice"
, array(
"choices" => array("student"=>"Student", "staff"=>"Staff")
, "expanded" => true
, "label_attr" => array(
"class" => "normal"
)
, "multiple" => false
, "required" => false
)
)
Thanks for the help.
I'm pretty sure its not meant to overwrite in an easy way as ichabrand already wrote before :)
Not sure if this is the answer but i've seen it another day:
{{ form_widget(form.persontype[0], {"id":"student"}) }}
This id is made with your formulaire name and your field name : "formulaire[field]", i'm not sure than you can overpass that.
If you want to add custom field, you have to add 'allow_extra_fields' => true in your form options.
If you use default form_div_layout as your form components template, you can notice that attributes for each of your inputs generated using the next block:
{%- block widget_attributes -%}
id="{{ id }}" name="{{ full_name }}"
...
So to change id, you have 2 options:
rewrite widget_attributes by using custom form theme
overwrite buildView or finishView of your form type and after call of parent::buildView just add some code to modify vars['id'] of needed control
I have a form that has a select input that called customer_id. This field is not required, and I fetch the options via the Customer Model. My code looks like this:
{!! Form::select('customer', $customers->lists('email', 'id'), null, ['class' => 'form-control']) !!}
so far so good, right? but the thing is that when I don't want to choose a customer, I can't choose a blank option. Is there a way to add a blank option so I wouldn't need to pick a customer all the time?
[''=>'---']+$customers->lists('email', 'id')->toArray()
or
array_merge([''=>'---'], $customers->lists('email', 'id')->toArray())
I have an "artist" resource, and on the show route page I have a form. I am using Laravel Blade syntax. As part of this form, I am trying to send the page ID to the back end of a Laravel 4 project. I am doing it this way:
{{Form::hidden('artist-id',null, array(
'id' => '{{$artist->id}}',
));}}
However, when using this, the browser throws an error, because it is not rendering the $artist->id variable within the brackets before the outside brackets of the input form.
Is there a way around this or another way to pass back this variable for the resource? Thank you!
So anything inside the blade tags {{ }} is treated as standard PHP. Using further {{ }} inside existing blade tags is just going to throw a big error.
Because anything inside the blade tags is treated as PHP you can simply do the following
{{ Form::hidden('artist-id', null, ['id' => $artist->id]) }}
Although posting that input isn't going to give you the value you want, because the value supplied is null. The id attribute is the html ID given to the html attribute. You need the following to set the value on the input, which will then be posted in with your form data
{{ Form::hidden('artist-id', $artist->id) }}
You don't need to nest your blade call like that, this should work:
{{ Form::hidden('artist-id', null, array('id' => $artist->id)) }}
I'm new to laravel, in the view page I'm showing a Dropdown-List which is fetched from the database and based on that Dropdown-List value selection, I'm getting the corresponding value id. But I also want one more corresponding fields from database based on the Dropdown-List I'm selecting.
How to get it? Based on that values I want to do Javascript operation.
Here's my code:
{{
Form::select('asset_type_id',$assettype_list, Input::old('asset_type_id'),
array('class'=>'select2', 'onchange' => 'check(Input::get(this.value);)',
'style'=>'width:350px'))
}}
You cannot use Input::get(this.value) in your onchange as it will be printed literally. You can just use the code without the Input::get. Of course, this all depends on how you are using the value in your javascript.
{{
Form::select('asset_type_id',$assettype_list, Input::old('asset_type_id'),
array('class'=>'select2', 'onchange' => 'check(this.value)',
'style'=>'width:350px'))
}}
I'm working on an Laravel 4 project and we have an view with an dynamic form.
Form::text('title')
<ul>
<li>Form::text('movie_actor[]')</li>
<li>Form::text('movie_actor[]')</li>
<li>Form::text('movie_actor[]')</li>
...
</ul>
I've read that you need to set the validation for the multi fields to array. So I added the validation rules like so:
$v = Validator::make(Input::all(), array('title' => 'required', 'movie_actor' => 'array'));
When I enter some actors, leave the title empty and submit the form, then the user is redirected to the same page with:
return Redirect::route('movies.create')->withInput();
The problem is that I get the error htmlentities() expects parameter 1 to be string, array given.
The population works when I remove the actor inputs from the view or change the actor text fields to selects fields. But that is not what I want.
How can I populate the multi-text fields?
I had same issue too. I haven't figure out exactly why its happen but looks like those text input name should be "string" not array which means, you should do like follow:
<li>Form::text('movie_actor[0]')</li>
<li>Form::text('movie_actor[1]')</li>
<li>Form::text('movie_actor[2]')</li>
The differences are you need to manually add an index to those name array.