Package Data | |
---|---|
Maintainer Username: | Intentor |
Maintainer Contact: | support@intentor.com.br (André "Intentor" Martins) |
Package Create Date: | 2015-03-12 |
Package Last Update: | 2019-11-17 |
Home Page: | |
Language: | HTML |
License: | MIT |
Last Refreshed: | 2024-12-15 03:04:45 |
Package Statistics | |
---|---|
Total Downloads: | 775 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 10 |
Total Watchers: | 3 |
Total Forks: | 3 |
Total Open Issues: | 0 |
Form helpers for Laravel 5
Laravel Form provides a series of helpers for form creation in PHP pages and Blade templates.
Compatible with Laravel 5.
At composer.json
of your Laravel installation, add the following require line:
{
"require": {
"intentor/laravel-form": "~1.0"
}
}
Run composer update
to add the package to your Laravel app.
At config/app.php
, add the Service Provider and the Facade:
'providers' => [
'Intentor\LaravelForm\ServiceProvider',
]
//...
'aliases' => [
'Form' => 'Intentor\LaravelForm\Facade'
]
At composer.json
of your Laravel installation, add the following require line:
{
"require": {
"intentor/laravel-form": "~2.0"
}
}
Run composer update
to add the package to your Laravel app.
At config/app.php
, add the Service Provider and the Facade:
'providers' => [
Intentor\LaravelForm\ServiceProvider::class,
]
//...
'aliases' => [
'Form' => Intentor\LaravelForm\Facade::class,
]
To create a form, you can user either Blade helpers or the Form
Facade.
Using Blade helpers:
@form_open(action('SomeController@action'))
@form_close
Using Facades:
{!! Form::open(action('SomeController@action')) !!}
{!! Form::close() !!}
Any controls you want to create must be placed between the opening and closing of the form.
Using Blade helpers:
@form_open(action('SomeController@action'))
@form_text('name', 'Name')
@form_buttons('Send', 'Reset')
@form_close
Using Facades:
{!! Form::open(action('SomeController@action')) !!}
{!! Form::text('name', 'Name') !!}
{!! Form::buttons('Send', 'Reset') !!}
{!! Form::close() !!}
Opens a form. See Themes for more details on form themes.
@form_open($url, $method = 'POST', $theme = null, $includeCsrfToken = true, $attributes = [])
{!! Form::open($url, $method = 'POST', $theme = null, $includeCsrfToken = true, $attributes = []) !!}
$url
Action URL.$method
Form method.$theme
Controls' theme. It's a subfolder on the partials.form folder.$includeCsrfToken
Indicates whether the CSRF token should be included.$attributes
Form attributes.Opens a form for a model. See Themes for more details on form themes.
@form_
{!! Form::model($model, $url, $method = 'POST', $theme = null, $includeCsrfToken = true, $attributes = []) !!}
$model
Model object.$url
Action URL.$method
Form method.$theme
Controls' theme. It's a subfolder on the partials.form folder.$includeCsrfToken
Indicates whether the CSRF token should be included.$attributes
Form attributes.Closes a from.
@form_close
{!! Form::close() !!}
None.
Creates a label.
@form_label($text, $field = null, $attributes = [])
{!! Form::label($text, $field = null, $attributes = []) !!}
$text
Label text.$field
Related field name.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a readonly control.
@form_readonly($label, $text, $attributes = [])
{!! Form::readonly($label, $text, $attributes = []) !!}
$label
Label text.$text
Field text.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a hidden field.
@form_hidden($name, $value = null, $attributes = [])
{!! Form::hidden($name, $value = null, $attributes = []) !!}
$name
Field name.$value
Field value.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a text field.
@form_text($name, $label = null, $attributes = [])
{!! Form::text($name, $label = null, $attributes = []) !!}
$name
Field name.$label
Field label.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a textarea field.
@form_textarea($name, $label = null, $attributes = [])
{!! Form::textarea($name, $label = null, $attributes = []) !!}
$name
Field name.$label
Field label.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates an e-mail field.
@form_email($name, $label = null, $attributes = [])
{!! Form::email($name, $label = null, $attributes = []) !!}
$name
Field name.$label
Field label.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates an URL field.
@form_url($name, $label = null, $attributes = [])
{!! Form::url($name, $label = null, $attributes = []) !!}
$name
Field name.$label
Field label.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a number field.
@form_number($name, $label = null, $min = 0, $max = 9999, $step = 1, $attributes = [])
{!! Form::number($name, $label = null, $min = 0, $max = 9999, $step = 1, $attributes = []) !!}
$name
Field name.$label
Field label.$min
Minimum number.$max
Maximum number.$step
Combined with the min value, defines the acceptable numbers in the range.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a password field.
@form_password($name, $label = null, $attributes = [])
{!! Form::password($name, $label = null, $attributes = []) !!}
$name
Field name.$label
Field label.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a checkbox field.
@form_checkbox($name, $label = null, $value = 1, $attributes = [])
{!! Form::checkbox($name, $label = null, $value = 1, $attributes = []) !!}
$name
Field name.$label
Field label.$value
Field value.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a radio field.
@form_radio($name, $label = null, $attributes = [])
{!! Form::radio($name, $label = null, $attributes = []) !!}
$name
Field name.$label
Field label.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a checkbox group.
@form_checkbox_group($name, $label = null, $list = [], $selected = [], $attributes = [])
{!! Form::checkboxGroup($name, $label = null, $list = [], $selected = [], $attributes = []) !!}
$name
Field name.$label
Field label.$list
Item's list. Format: [ 'value' => '', 'text' => '' ]. Use modelToList to generate a list from models.$selected
Selected values. Format: [ 'value', 'value', ... ]. Use modelToSelected to generate values from models.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a radio group.
@form_radio_group($name, $label = null, $list = [], $selected = null, $attributes = [])
{!! Form::radioGroup($name, $label = null, $list = [], $selected = null, $attributes = []) !!}
$name
Field name.$label
Field label.$list
Item's list. Format: [ 'value' => '', 'text' => '' ]. Use modelToList to generate a list from models.$selected
Selected value.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a dropdown field.
@form_dropdown($name, $label = null, $list = [], $empty = null, $selected = null, $attributes = [])
{!! Form::dropdown($name, $label = null, $list = [], $empty = null, $selected = null, $attributes = []) !!}
$name
Field name.$label
Field label.$list
Item's list. Format: [ 'value' => 'text', 'text' => '' ]. Use modelToList to generate a list from models.$empty
Empty value text. If no text is provided, there will not be an empty option.$selected
Selected value.$attributes
Element attributes. Format: [ 'attribute' => 'value' ].Creates a submit button.
@form_submit($label)
{!! Form::submit($label) !!}
$label
Control label.Creates a reset button.
@form_reset($label)
{!! Form::reset($label) !!}
$label
Control label.Creates form buttons (submit and reset).
@form_buttons($submitLabel, $resetLabel = null)
{!! Form::buttons($submitLabel, $resetLabel = null) !!}
$submitLabel
Submit button label.$resetLabel
Reset button label. If no label is given, the button is not created.Generates an array compatible with lists (dropdowns, checkbox groups, etc.).
Form::modelToList($model, $valueField, $textField)
$model
Model to be converted.$valueField
Field on data that is the value.$textField
Field on data that is the text.Generates an array of selected values.
Form::modelToSelected($model, $valueField)
$model
Model to be converted.$valueField
Field on data that is the value.Themes are a way to customize the look of forms using partial views.
There are three different themes available:
All themes are subfolders at src/resources/views/partials/form
folder.
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.
Each helper has its own Blade template file, which can then be customized.
Note: the name of the theme's folder is the name that must be used when setting the theme.
Please see CHANGELOG.md.
Found a bug? Please create an issue on the GitHub project page or send a pull request if you have a fix or extension.
You can also send me a message at support@intentor.com.br to discuss more obscure matters about the component.
Licensed under the The MIT License (MIT). Please see LICENSE for more information.