HTML

Introduction

The HTML service is fork of Laravel HTML 4.2 component. It provides various functions for rapidly building application forms.

Opening A Form

{!! Form::open(['url' => 'foo/bar']) !!}
    //
{!! Form::close() !!}

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

{!! Form::open(['url' => 'foo/bar', 'method' => 'get']) !!}

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

{!! Form::open(['url' => 'foo/bar', 'files' => true]) !!}

Labels

Generating A Label Element

{!! Form::label('email', 'E-Mail Address') !!}

Specifying Extra HTML Attributes

{!! Form::label('email', 'E-Mail Address', ['class' => 'awesome']) !!}

Text, Text Area, Password & Hidden Fields

Generating A Text Input

{!! Form::text('username') !!}

Specifying A Default Value

{!! Form::text('email', 'example@gmail.com') !!}

Generating A Password Input

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

Generating Other Inputs

{!! Form::email($name, $value = null, $attributes = []) !!}
Form::file($name, $attributes = []) !!}

Checkboxes and Radio Buttons

Generating A Checkbox Or Radio Input

{!! Form::checkbox('name', 'value') !!}
{!! Form::radio('name', 'value') !!}

Generating A Checkbox Or Radio Input That Is Checked

{!! Form::checkbox('name', 'value', true) !!}
{!! Form::radio('name', 'value', true) !!}

Number

Generating A Number Input

{!! Form::number('name', 'value') !!}

File Input

Generating A File Input

{!! Form::file('image') !!}

Drop-Down Lists

Generating A Drop-Down List

{!! Form::select('size', ['L' => 'Large', 'S' => 'Small']) !!}

Generating A Drop-Down List With Selected Default

{!! Form::select('size', ['L' => 'Large', 'S' => 'Small'], 'S') !!}

Generating A Grouped List

{!! Form::select('animal', [
    'Cats' => ['leopard' => 'Leopard'],
    'Dogs' => ['spaniel' => 'Spaniel'],
]) !!}

Generating A Drop-Down List With A Range

{!! Form::selectRange('number', 10, 20) !!}

Generating A List With Month Names

{!! Form::selectMonth('month') !!}

Buttons

Generating A Submit Button

{!! Form::submit('Click Me!') !!}

Custom Macros

Registering A Form Macro

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('myField', function() {
    return '<input type="awesome">';
});

Now you can call your macro using its name:

Calling A Custom Form Macro

{!! Form::myField() !!}