Creating a Hidden Input Field


You want to create a hidden input field for your form.

You know you could use the <input type="hidden"...> format but you want to do it the Laravel way.


Use the Form::hidden() method.

Usually, this is used in Blade templates.

Just pass the name and value to the method.

{{ Form::hidden('invisible', 'secret') }}

This creates a very simple element which looks like the following.

<input name="invisible" type="hidden" value="secret">

To add other attributes, pass a third argument to the method. This third argument must be an array.

{{ Form::hidden('invisible', 'secret', array('id' => 'invisible_id')) }}

Now the input has an id attribute.

<input id="invisible_id" name="invisible" type="hidden" value="secret">


This method uses the Form::input() method, passing “hidden” as the type.

NOTE If you’ve bound the form to a model using Form::model() and the model has the same named attribute, then the value will come from the model. See Creating a New Model Based Form for details.

About the author