Creating a Password Input Field

Problem

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

You know you could use the <input type="password"...> format but you want to use the Form facade.

Solution

Use the Form::password() method.

Usually, this is used in Blade templates.

The simplest way to use this method is to only pass the name.

{{ Form::password('secret') }}

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

<input name="secret" type="password" value="">

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

{{ Form::password('secret', array('class' => 'field')) }}

Now the password field has a class attribute.

<input class="field" name="secret" type="password" value="">

Discussion

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

comments powered by Disqus