Creating an Email Input Field


You want to create an email input field for your form.

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


Use the Form::email() method.

Usually, this is used in Blade templates.

The simplest form of this method is to only pass the name.

{{ Form::email('email_address') }}

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

<input name="email_address" type="email">

You can also pass an additional value option.

{{ Form::text('email_address', '') }}

Producing the following.

<input name="email_address" type="email" value="">

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

{{ Form::email('email_address', '', ['class' => 'field']) }}

Now the input has a class attribute.

<input class="field" name="email_address" type="email" \

(The backslash is used above to format output for small screens.)


This method uses the Form::input() method, passing "email" as the type.

Also, please note that the value will first come from Flash Session Input, only secondly will the value argument be used. This means if your previous request was this form it will automatically display the value the user last entered.

NOTE: If you've bound the form to a model using Form::model(), then the order of precedence for determining which value to display is different. See Creating a New Model Based Form for details.

comments powered by Disqus