Entering Laravel 4 form text

Hello, I am currently working with Laravel 4 formats. I am trying to create text input with a specific class without selecting the "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 .) If you do not add a default value:

 {{ Form::text('first_name', 'Some Value', array('class' => 'first_name')) }} 

The default value fills the field and must be deleted before entering a new value. Therefore, it cannot even be used as a seat holder.

Thanks in advance,

Dan

+7
php laravel laravel-4 blade
source share
3 answers

Set null instead of value. (do not send empty string "" )

This will come in handy in the future if you intend to work with binding to the form of the form ( http://laravel.com/docs/html#form-model-binding ), because null will specify the value of this model attribute.

+20
source share

You can pass an empty value "" like,

 {{ Form::text('first_name', '', array('class' => 'first_name')) }} 

Since the Laravel 4 HTML Form Builder API will accept the first parameter as name , the second parameter is value , which is null by default, and the third parameter options array is the default parameter empty array .

So basically you can create text input by passing only a name like

 {{ Form::text('first_name') }} 

And if you plan on passing parameters that are the third argument, you must also pass the second argument.

See the Doc API here http://laravel.com/api/source-class-Illuminate.Html.FormBuilder.html#235-246

+6
source share

I was better off using Input::old('first_name') for your default instead of "", for example:

{{ Form::text('first_name', Input::old('first_name')) }}

Thus, if you return to the form with invalid data and skip the form input, it will reload the old input that the user previously entered. In this case, first_name can be mapped to the first_name field in the database table.

Edit: Yes, the third parameter is an array of input parameters such as text field identifier, size, etc. or any other HTML attribute.

Keenan :)

-2
source share

All Articles