In this tutorial, you will learn how to use Laravel’s form builder. The form builder will be demonstrated to facilitate the building of the following elements:

  • Form (open and close)
  • Label
  • Input (text, HTML5 password, HTML5 e-mail, and so on.)
  • Checkbox
  • Submit
  • Anchor tags (href links)

Finally, we’ll see an example of how to use the form builder to create the month, date, and year selection elements for the accommodations reservation software form, and how to create a macro to reduce the code duplication.

History

The form builder package in Laravel 4 is called HTML. This was used to help you create HTML, particularly developers who also have to perform web designer duties but prefer to use Laravel facades and helper methods. For example, the following Laravel facade select() method, where the options for the language, British and American English in this example, are passed as an array parameter:

Form::select('language', ['en-us' => 'English (US)','en-gb' => 'English (UK)']);

This can be used as an alternative to the standard HTML, which requires much more repetitious code, as shown in the following code:

<select name="language">
    <option value="en-us">English (US)</option>
    <option value="en-gb">English (UK)</option>
</select>

Since frameworks are constantly evolving, they need to adapt to fulfill the needs of most of their users. Also, whenever possible, they should continue to be more efficient. In some cases, this means rewriting or refactoring pieces of the framework, adding features, or even removing them.

 

Advertisements