<commit_before># Forms & HTML

- [Opening A Form](#opening-a-form)
- [CSRF Protection](#csrf-protection)
- [Form Model Binding](#form-model-binding)
- [Labels](#labels)
- [Text, Text Area, Password & Hidden Fields](#text)
- [Checkboxes and Radio Buttons](#checkboxes-and-radio-buttons)
- [File Input](#file-input)
- [Drop-Down Lists](#drop-down-lists)
- [Buttons](#buttons)
- [Custom Macros](#custom-macros)

<a name="opening-a-form"></a>
## Opening A Form

**Opening A Form**

	{{ Form::open(array('url' => 'foo/bar')) }}
		//
	{{ Form::close() }}

By default, a `POST` method will be assumed; however, you are free to specify another method:

	echo Form::open(array('url' => 'foo/bar', 'method' => 'put'))

> **Note:** Since HTML forms only support `POST` and `GET`, `PUT` and `DELETE` methods will be spoofed by automatically adding a `_method` hidden field to your form.

You may also open forms that point to named routes or controller actions:

	echo Form::open(array('route' => 'route.name'))

	echo Form::open(array('action' => 'Controller@method'))

You may pass in route parameters as well:

	echo Form::open(array('route' => array('route.name', $user->id)))

	echo Form::open(array('action' => array('Controller@method', $user->id)))

If your form is going to accept file uploads, add a `files` option to your array:

	echo Form::open(array('url' => 'foo/bar', 'files' => true))

<a name="csrf-protection"></a>
## CSRF Protection

Laravel provides an easy method of protecting your application from cross-site request forgeries. First, a random token is placed in your user's session. Don't sweat it, this is done automatically. The CSRF token will be added to your forms as a hidden field automatically. However, if you wish to generate the HTML for the hidden field, you may use the `token` method:

**Adding The CSRF Token To A Form**

	echo Form::token();

**Attaching The CSRF Filter To A Route**

	Route::post('profile', array('before' => 'csrf', function()
	{
		//
	}));

<a name="form-model-binding"></a>
## Form Model Binding

Often, you will want to populate a form based on the contents of a model. To do so, use the `Form::model` method:

**Opening A Model Form**

	echo Form::model($user, array('route' => array('user.update', $user->id)))

Now, when you generate a form element, like a text input, the model's value matching the field's name will automatically be set as the field value. So, for example, for a text input named `email`, the user model's `email` attribute would be set as the value. However, there's more! If there is an item in the Session flash data matching the input name, that will take precedence over the model's value. So, the priority looks like this:

1. Session Flash Data (Old Input)
2. Explicitly Passed Value
3. Model Attribute Data

This allows you to quickly build forms that not only bind to model values, but easily re-populate if there is a validation error on the server!

> **Note:** When using `Form::model`, be sure to close your form with `Form::close`!

<a name="labels"></a>
## Labels

**Generating A Label Element**

	echo Form::label('email', 'E-Mail Address');

**Specifying Extra HTML Attributes**

	echo Form::label('email', 'E-Mail Address', array('class' => 'awesome'));

> **Note:** After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.

<a name="text"></a>
## Text, Text Area, Password & Hidden Fields

**Generating A Text Input**

	echo Form::text('username');

**Specifying A Default Value**

	echo Form::text('email', '<EMAIL>');

> **Note:** The *hidden* and *textarea* methods have the same signature as the *text* method.

**Generating A Password Input**

	echo Form::password('password');
	
**Generating Other Inputs**

	echo Form::date($name, $value = null, $attributes = array());
	echo Form::email($name, $value = null, $attributes = array());
	echo Form::file($name, $attributes = array());
	echo Form::number($name, $value = null, $attributes = array());
	echo Form::search($name, $value = null, $attributes = array());
	echo Form::telephone($name, $value = null, $attributes = array());
	echo Form::url($name, $value = null, $attributes = array());
	
<a name="checkboxes-and-radio-buttons"></a>
## Checkboxes and Radio Buttons

**Generating A Checkbox Or Radio Input**

	echo Form::checkbox('name', 'value');
	
	echo Form::radio('name', 'value');

**Generating A Checkbox Or Radio Input That Is Checked**

	echo Form::checkbox('name', 'value', true);
	
	echo Form::radio('name', 'value', true);

<a name="file-input"></a>
## File Input

**Generating A File Input**<commit_msg>Update documentation for missing methods.<commit_after># Forms & HTML

- [Opening A Form](#opening-a-form)
- [CSRF Protection](#csrf-protection)
- [Form Model Binding](#form-model-binding)
- [Labels](#labels)
- [Text, Text Area, Password & Hidden Fields](#text)
- [Checkboxes and Radio Buttons](#checkboxes-and-radio-buttons)
- [File Input](#file-input)
- [Drop-Down Lists](#drop-down-lists)
- [Buttons](#buttons)
- [Custom Macros](#custom-macros)

<a name="opening-a-form"></a>
## Opening A Form

**Opening A Form**

	{{ Form::open(array('url' => 'foo/bar')) }}
		//
	{{ Form::close() }}

By default, a `POST` method will be assumed; however, you are free to specify another method:

	echo Form::open(array('url' => 'foo/bar', 'method' => 'put'))

> **Note:** Since HTML forms only support `POST` and `GET`, `PUT` and `DELETE` methods will be spoofed by automatically adding a `_method` hidden field to your form.

You may also open forms that point to named routes or controller actions:

	echo Form::open(array('route' => 'route.name'))

	echo Form::open(array('action' => 'Controller@method'))

You may pass in route parameters as well:

	echo Form::open(array('route' => array('route.name', $user->id)))

	echo Form::open(array('action' => array('Controller@method', $user->id)))

If your form is going to accept file uploads, add a `files` option to your array:

	echo Form::open(array('url' => 'foo/bar', 'files' => true))

<a name="csrf-protection"></a>
## CSRF Protection

Laravel provides an easy method of protecting your application from cross-site request forgeries. First, a random token is placed in your user's session. Don't sweat it, this is done automatically. The CSRF token will be added to your forms as a hidden field automatically. However, if you wish to generate the HTML for the hidden field, you may use the `token` method:

**Adding The CSRF Token To A Form**

	echo Form::token();

**Attaching The CSRF Filter To A Route**

	Route::post('profile', array('before' => 'csrf', function()
	{
		//
	}));

<a name="form-model-binding"></a>
## Form Model Binding

Often, you will want to populate a form based on the contents of a model. To do so, use the `Form::model` method:

**Opening A Model Form**

	echo Form::model($user, array('route' => array('user.update', $user->id)))

Now, when you generate a form element, like a text input, the model's value matching the field's name will automatically be set as the field value. So, for example, for a text input named `email`, the user model's `email` attribute would be set as the value. However, there's more! If there is an item in the Session flash data matching the input name, that will take precedence over the model's value. So, the priority looks like this:

1. Session Flash Data (Old Input)
2. Explicitly Passed Value
3. Model Attribute Data

This allows you to quickly build forms that not only bind to model values, but easily re-populate if there is a validation error on the server!

> **Note:** When using `Form::model`, be sure to close your form with `Form::close`!

<a name="labels"></a>
## Labels

**Generating A Label Element**

	echo Form::label('email', 'E-Mail Address');

**Specifying Extra HTML Attributes**

	echo Form::label('email', 'E-Mail Address', array('class' => 'awesome'));

> **Note:** After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.

<a name="text"></a>
## Text, Text Area, Password & Hidden Fields

**Generating A Text Input**

	echo Form::text('username');

**Specifying A Default Value**

	echo Form::text('email', '<EMAIL>');

> **Note:** The *hidden* and *textarea* methods have the same signature as the *text* method.

**Generating A Password Input**

	echo Form::password('password');
	
**Generating Other Inputs**

	echo Form::email($name, $value = null, $attributes = array());
	echo Form::file($name, $attributes = array());
	
<a name="checkboxes-and-radio-buttons"></a>
## Checkboxes and Radio Buttons

**Generating A Checkbox Or Radio Input**

	echo Form::checkbox('name', 'value');
	
	echo Form::radio('name', 'value');

**Generating A Checkbox Or Radio Input That Is Checked**

	echo Form::checkbox('name', 'value', true);
	
	echo Form::radio('name', 'value', true);

<a name="file-input"></a>
## File Input

**Generating A File Input**
{'fraction_non_alphanumeric': 0.1488655229662424, 'fraction_numerical': 0.0006640841173215274, 'mean_word_length': 4.886644951140065, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4676628', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2624, 'n_words': 1113}