Hello I'm currently working with Laravel 4 forms. I'm struggling to generate a text input with a specific class without choosing a 'default value'. I want to do the following:
{{ Form::text('first_name', array('class' => 'first_name')) }}
However I get this error (htmlentities() expects parameter 1 to be string, array given
.) unless I add a default value:
{{ Form::text('first_name', 'Some Value', array('class' => 'first_name')) }}
The default value then populates the field and needs to be deleted before entering a new value. So it can't even be used like a place holder.
Thank you in advance,
Dan
Instead of a value, supply null
. (do no supply empty string ""
)
This will come in handy in the future if you are going to work with Form Model Binding (http://laravel.com/docs/html#form-model-binding) because null
will give the value of the given model attribute.
You can pass an empty value ""
like,
{{ Form::text('first_name', '', array('class' => 'first_name')) }}
Because Laravel 4's HTML Form Builder
API will accept first parameter as name
, second parameter as value
which is null
by default and the third parameter as options array
which is an empty array
by default.
So basically you can build text input by passing only name like,
{{ Form::text('first_name') }}
And if you are planning to pass options which is the third argument, you must pass second argument also.
See API Doc here http://laravel.com/api/source-class-Illuminate.Html.FormBuilder.html#235-246
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With