Note: All input data displayed in form elements is filtered through the HTML::entities method.
echo Form::open();
echo Form::open('user/profile', 'PUT');
echo Form::open_secure('user/profile');
echo Form::open('user/profile', 'POST', array('class' => 'awesome'));
echo Form::open_for_files('users/profile');
echo Form::open_secure_for_files('users/profile');
echo Form::close();
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. Next, use the token method to generate a hidden form input field containing the random token on your form:
echo Form::token();
Route::post('profile', array('before' => 'csrf', function()
{
//
}));
$token = Session::token();
Note: You must specify a session driver before using the Laravel CSRF protection facilities.
Further Reading:
echo Form::label('email', 'E-Mail Address');
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.
echo Form::text('username');
echo Form::text('email', 'example@gmail.com');
Note: The hidden and textarea methods have the same signature as the text method. You just learned three methods for the price of one!
echo Form::password('password');
echo Form::checkbox('name', 'value');
echo Form::checkbox('name', 'value', true);
Note: The radio method has the same signature as the checkbox method. Two for one!
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'));
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S');
echo Form::submit('Click Me!');
Note: Need to create a button element? Try the button method. It has the same signature as submit.
It's easy to define your own custom Form class helpers called "macros". Here's how it works. First, simply register the macro with a given name and a Closure:
Form::macro('my_field', function()
{
return '<input type="awesome">';
});
Now you can call your macro using its name:
echo Form::my_field();