
Form helpers for Laravel 5, (*1)
Currently the project is DISCONTINUED. However, feel free to fork it and continue its development!, (*2)
Contents
- Introduction
- Installation
- Quick start
-
Helpers
-
Utilities
- Themes
- Changelog
- Support
- License
Introduction
Laravel Form provides a series of helpers for form creation in PHP pages and Blade templates., (*3)
Compatible with Laravel 5., (*4)
Installation
Laravel 5.0
At composer.json
of your Laravel installation, add the following require line:, (*5)
``` json
{
"require": {
"intentor/laravel-form": "~1.0"
}
}, (*6)
Run `composer update` to add the package to your Laravel app.
At `config/app.php`, add the Service Provider and the Facade:
```php
'providers' => [
'Intentor\LaravelForm\ServiceProvider',
]
//...
'aliases' => [
'Form' => 'Intentor\LaravelForm\Facade'
]
Laravel 5.1+
At composer.json
of your Laravel installation, add the following require line:, (*7)
``` json
{
"require": {
"intentor/laravel-form": "~2.0"
}
}, (*8)
Run `composer update` to add the package to your Laravel app.
At `config/app.php`, add the Service Provider and the Facade:
```php
'providers' => [
Intentor\LaravelForm\ServiceProvider::class,
]
//...
'aliases' => [
'Form' => Intentor\LaravelForm\Facade::class,
]
Quick start
To create a form, you can user either Blade helpers or the Form
Facade., (*9)
Using Blade helpers:, (*10)
@form_open(action('SomeController@action'))
@form_close
Using Facades:, (*11)
{!! Form::open(action('SomeController@action')) !!}
{!! Form::close() !!}
Any controls you want to create must be placed between the opening and closing of the form., (*12)
Using Blade helpers:, (*13)
@form_open(action('SomeController@action'))
@form_text('name', 'Name')
@form_buttons('Send', 'Reset')
@form_close
Using Facades:, (*14)
{!! Form::open(action('SomeController@action')) !!}
{!! Form::text('name', 'Name') !!}
{!! Form::buttons('Send', 'Reset') !!}
{!! Form::close() !!}
Helpers
Opens a form. See Themes for more details on form themes., (*15)
Blade helper
@form_open($url, $method = 'POST', $theme = null, $includeCsrfToken = true, $attributes = [])
Facade
{!! Form::open($url, $method = 'POST', $theme = null, $includeCsrfToken = true, $attributes = []) !!}
Parameters
- string
$url
Action URL.
- string
$method
Form method.
- bool
$theme
Controls' theme. It's a subfolder on the partials.form folder.
- bool
$includeCsrfToken
Indicates whether the CSRF token should be included.
- array
$attributes
Form attributes.
Opens a form for a model. See Themes for more details on form themes., (*16)
Blade helper
@form_
Facade
{!! Form::model($model, $url, $method = 'POST', $theme = null, $includeCsrfToken = true, $attributes = []) !!}
Parameters
- object
$model
Model object.
- string
$url
Action URL.
- string
$method
Form method.
- bool
$theme
Controls' theme. It's a subfolder on the partials.form folder.
- bool
$includeCsrfToken
Indicates whether the CSRF token should be included.
- array
$attributes
Form attributes.
Closes a from., (*17)
Blade helper
@form_close
Facade
{!! Form::close() !!}
Parameters
None., (*18)
Creates a label., (*19)
Blade helper
@form_label($text, $field = null, $attributes = [])
Facade
{!! Form::label($text, $field = null, $attributes = []) !!}
Parameters
- string
$text
Label text.
- string
$field
Related field name.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a readonly control., (*20)
Blade helper
@form_readonly($label, $text, $attributes = [])
Facade
{!! Form::readonly($label, $text, $attributes = []) !!}
Parameters
- string
$label
Label text.
- string
$text
Field text.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a hidden field., (*21)
Blade helper
@form_hidden($name, $value = null, $attributes = [])
Facade
{!! Form::hidden($name, $value = null, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$value
Field value.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
text
Creates a text field., (*22)
Blade helper
@form_text($name, $label = null, $attributes = [])
Facade
{!! Form::text($name, $label = null, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
textarea
Creates a textarea field., (*23)
Blade helper
@form_textarea($name, $label = null, $attributes = [])
Facade
{!! Form::textarea($name, $label = null, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates an e-mail field., (*24)
Blade helper
@form_email($name, $label = null, $attributes = [])
Facade
{!! Form::email($name, $label = null, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates an URL field., (*25)
Blade helper
@form_url($name, $label = null, $attributes = [])
Facade
{!! Form::url($name, $label = null, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a number field., (*26)
Blade helper
@form_number($name, $label = null, $min = 0, $max = 9999, $step = 1, $attributes = [])
Facade
{!! Form::number($name, $label = null, $min = 0, $max = 9999, $step = 1, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- int
$min
Minimum number.
- int
$max
Maximum number.
- int
$step
Combined with the min value, defines the acceptable numbers in the range.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a password field., (*27)
Blade helper
@form_password($name, $label = null, $attributes = [])
Facade
{!! Form::password($name, $label = null, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a checkbox field., (*28)
Blade helper
@form_checkbox($name, $label = null, $value = 1, $attributes = [])
Facade
{!! Form::checkbox($name, $label = null, $value = 1, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- string
$value
Field value.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a radio field., (*29)
Blade helper
@form_radio($name, $label = null, $attributes = [])
Facade
{!! Form::radio($name, $label = null, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a checkbox group., (*30)
Blade helper
@form_checkbox_group($name, $label = null, $list = [], $selected = [], $attributes = [])
Facade
{!! Form::checkboxGroup($name, $label = null, $list = [], $selected = [], $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- array
$list
Item's list. Format: [ 'value' => '', 'text' => '' ]. Use modelToList to generate a list from models.
- array
$selected
Selected values. Format: [ 'value', 'value', ... ]. Use modelToSelected to generate values from models.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a radio group., (*31)
Blade helper
@form_radio_group($name, $label = null, $list = [], $selected = null, $attributes = [])
Facade
{!! Form::radioGroup($name, $label = null, $list = [], $selected = null, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- array
$list
Item's list. Format: [ 'value' => '', 'text' => '' ]. Use modelToList to generate a list from models.
- string
$selected
Selected value.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a dropdown field., (*32)
Blade helper
@form_dropdown($name, $label = null, $list = [], $empty = null, $selected = null, $attributes = [])
Facade
{!! Form::dropdown($name, $label = null, $list = [], $empty = null, $selected = null, $attributes = []) !!}
Parameters
- string
$name
Field name.
- string
$label
Field label.
- array
$list
Item's list. Format: [ 'value' => 'text', 'text' => '' ]. Use modelToList to generate a list from models.
- string
$empty
Empty value text. If no text is provided, there will not be an empty option.
- string
$selected
Selected value.
- array
$attributes
Element attributes. Format: [ 'attribute' => 'value' ].
Creates a submit button., (*33)
Blade helper
@form_submit($label)
Facade
{!! Form::submit($label) !!}
Parameters
- string
$label
Control label.
Creates a reset button., (*34)
Blade helper
@form_reset($label)
Facade
{!! Form::reset($label) !!}
Parameters
- string
$label
Control label.
Creates form buttons (submit and reset)., (*35)
Blade helper
@form_buttons($submitLabel, $resetLabel = null)
Facade
{!! Form::buttons($submitLabel, $resetLabel = null) !!}
Parameters
- string
$submitLabel
Submit button label.
- string
$resetLabel
Reset button label. If no label is given, the button is not created.
Utilities
Generates an array compatible with lists (dropdowns, checkbox groups, etc.)., (*36)
Facade
Form::modelToList($model, $valueField, $textField)
Parameters
- object
$model
Model to be converted.
- string
$valueField
Field on data that is the value.
- string
$textField
Field on data that is the text.
Generates an array of selected values., (*37)
Facade
Form::modelToSelected($model, $valueField)
Parameters
- object
$model
Model to be converted.
- string
$valueField
Field on data that is the value.
Themes
Themes are a way to customize the look of forms using partial views., (*38)
Available themes
There are three different themes available:, (*39)
-
default: a simple form theme without any third party dependencies.
-
horizontal: default Bootstrap horizontal form (Requires Bootstrap 3).
-
vertical: default Bootstrap vertical form (Requires Bootstrap 3).
All themes are subfolders at src/resources/views/partials/form
folder., (*40)
Creating a custom theme
To create a custom theme, copy a base theme from vendor/intentor/laravel-form/src/resources/views/partials/form
at your local Laravel installation to the resources/views/partials/form
of your app., (*41)
Each helper has its own Blade template file, which can then be customized., (*42)
Note: the name of the theme's folder is the name that must be used when setting the theme., (*43)
Changelog
Please see CHANGELOG.md., (*44)
Support
Found a bug? Please create an issue on the GitHub project page or send a pull request if you have a fix or extension., (*45)
You can also send me a message at support@intentor.com.br to discuss more obscure matters about the component., (*46)
License
Licensed under the The MIT License (MIT). Please see LICENSE for more information., (*47)