PHP Class Collective\Html\FormBuilder

Inheritance: use trait Illuminate\Support\Traits\Macroable
Show file Open project: laravelcollective/html Class Usage Examples

Protected Properties

Property Type Description
$csrfToken string The CSRF token used by the form builder.
$html HtmlBuilder The HTML builder instance.
$labels array An array of label names we've created.
$model mixed The current model instance for the form.
$reserved array The reserved form open attributes.
$session Illuminate\Session\SessionInterface The session store implementation.
$skipValueTypes array The types of inputs to not fill values on by default.
$spoofedMethods array The form methods that should be spoofed, in uppercase.
$url Illuminate\Contracts\Routing\UrlGenerator The URL generator instance.
$view Illuminate\Contracts\View\Factory The View factory instance.

Public Methods

Method Description
__call ( string $method, array $parameters ) : Illuminate\Contracts\View\View | mixed Dynamically handle calls to the class.
__construct ( HtmlBuilder $html, Illuminate\Contracts\Routing\UrlGenerator $url, Illuminate\Contracts\View\Factory $view, string $csrfToken ) Create a new form builder instance.
button ( string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a button element.
checkbox ( string $name, mixed $value = 1, boolean $checked = null, array $options = [] ) : Illuminate\Support\HtmlString Create a checkbox input field.
close ( ) : string Close the current form.
color ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a color input field.
componentCall ( )
date ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a date input field.
datetime ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a datetime input field.
datetimeLocal ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a datetime-local input field.
email ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create an e-mail input field.
file ( string $name, array $options = [] ) : Illuminate\Support\HtmlString Create a file input field.
getIdAttribute ( string $name, array $attributes ) : string Get the ID attribute for a field name.
getSelectOption ( string $display, string $value, string $selected ) : Illuminate\Support\HtmlString Get the select option for the given value.
getSessionStore ( ) : Illuminate\Session\SessionInterface Get the session store implementation.
getValueAttribute ( string $name, string $value = null ) : mixed Get the value that should be assigned to the field.
hidden ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a hidden input field.
image ( string $url, string $name = null, array $attributes = [] ) : Illuminate\Support\HtmlString Create a HTML image input element.
input ( string $type, string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a form input field.
label ( string $name, string $value = null, array $options = [], boolean $escape_html = true ) : Illuminate\Support\HtmlString Create a form label element.
macroCall ( )
model ( mixed $model, array $options = [] ) : Illuminate\Support\HtmlString Create a new model based form builder.
number ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a number input field.
old ( string $name ) : mixed Get a value from the session's old input.
oldInputIsEmpty ( ) : boolean Determine if the old input is empty.
open ( array $options = [] ) : Illuminate\Support\HtmlString Open up a new HTML form.
password ( string $name, array $options = [] ) : Illuminate\Support\HtmlString Create a password input field.
radio ( string $name, mixed $value = null, boolean $checked = null, array $options = [] ) : Illuminate\Support\HtmlString Create a radio button input field.
reset ( string $value, array $attributes = [] ) : Illuminate\Support\HtmlString Create a HTML reset input element.
select ( string $name, array $list = [], string $selected = null, array $options = [] ) : Illuminate\Support\HtmlString Create a select box field.
selectMonth ( string $name, string $selected = null, array $options = [], string $format = '%B' ) : Illuminate\Support\HtmlString Create a select month field.
selectRange ( string $name, string $begin, string $end, string $selected = null, array $options = [] ) : Illuminate\Support\HtmlString Create a select range field.
selectYear ( ) : mixed Create a select year field.
setModel ( mixed $model ) : void Set the model instance on the form builder.
setSessionStore ( Illuminate\Session\SessionInterface $session ) Set the session store implementation.
submit ( string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a submit button element.
tel ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a tel input field.
text ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a text input field.
textarea ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a textarea input field.
time ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a time input field.
token ( ) : string Generate a hidden field with the current CSRF token.
url ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString Create a url input field.

Protected Methods

Method Description
checkable ( string $type, string $name, mixed $value, boolean $checked, array $options ) : Illuminate\Support\HtmlString Create a checkable input field.
formatLabel ( string $name, string | null $value ) : string Format the label value.
getAction ( array $options ) : string Get the form action from the options.
getAppendage ( string $method ) : string Get the form appendage for the given method.
getCheckboxCheckedState ( string $name, mixed $value, boolean $checked ) : boolean Get the check state for a checkbox input.
getCheckedState ( string $type, string $name, mixed $value, boolean $checked ) : boolean Get the check state for a checkable input.
getControllerAction ( array | string $options ) : string Get the action for an "action" option.
getMethod ( string $method ) : string Parse the form action method.
getModelValueAttribute ( string $name ) : mixed Get the model value that should be assigned to the field.
getRadioCheckedState ( string $name, mixed $value, boolean $checked ) : boolean Get the check state for a radio input.
getRouteAction ( array | string $options ) : string Get the action for a "route" option.
getSelectedValue ( string $value, string $selected ) : null | string Determine if the value is selected.
getUrlAction ( array | string $options ) : string Get the action for a "url" option.
missingOldAndModel ( string $name ) : boolean Determine if old input or model input exists for a key.
option ( string $display, string $value, string $selected ) : Illuminate\Support\HtmlString Create a select element option.
optionGroup ( array $list, string $label, string $selected ) : Illuminate\Support\HtmlString Create an option group form element.
placeholderOption ( $display, $selected ) : Illuminate\Support\HtmlString Create a placeholder select element option.
setQuickTextAreaSize ( array $options ) : array Set the text area size using the quick "size" attribute.
setTextAreaSize ( array $options ) : array Set the text area size on the attributes.
toHtmlString ( $html ) : Illuminate\Support\HtmlString Transform the string to an Html serializable object
transformKey ( string $key ) : mixed Transform key from array to dot syntax.

Method Details

__call() public method

Dynamically handle calls to the class.
public __call ( string $method, array $parameters ) : Illuminate\Contracts\View\View | mixed
$method string
$parameters array
return Illuminate\Contracts\View\View | mixed

__construct() public method

Create a new form builder instance.
public __construct ( HtmlBuilder $html, Illuminate\Contracts\Routing\UrlGenerator $url, Illuminate\Contracts\View\Factory $view, string $csrfToken )
$html HtmlBuilder
$url Illuminate\Contracts\Routing\UrlGenerator
$view Illuminate\Contracts\View\Factory
$csrfToken string

button() public method

Create a button element.
public button ( string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$value string
$options array
return Illuminate\Support\HtmlString

checkable() protected method

Create a checkable input field.
protected checkable ( string $type, string $name, mixed $value, boolean $checked, array $options ) : Illuminate\Support\HtmlString
$type string
$name string
$value mixed
$checked boolean
$options array
return Illuminate\Support\HtmlString

checkbox() public method

Create a checkbox input field.
public checkbox ( string $name, mixed $value = 1, boolean $checked = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value mixed
$checked boolean
$options array
return Illuminate\Support\HtmlString

close() public method

Close the current form.
public close ( ) : string
return string

color() public method

Create a color input field.
public color ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

componentCall() public method

public componentCall ( )

date() public method

Create a date input field.
public date ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

datetime() public method

Create a datetime input field.
public datetime ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

datetimeLocal() public method

Create a datetime-local input field.
public datetimeLocal ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

email() public method

Create an e-mail input field.
public email ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

file() public method

Create a file input field.
public file ( string $name, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$options array
return Illuminate\Support\HtmlString

formatLabel() protected method

Format the label value.
protected formatLabel ( string $name, string | null $value ) : string
$name string
$value string | null
return string

getAction() protected method

Get the form action from the options.
protected getAction ( array $options ) : string
$options array
return string

getAppendage() protected method

Get the form appendage for the given method.
protected getAppendage ( string $method ) : string
$method string
return string

getCheckboxCheckedState() protected method

Get the check state for a checkbox input.
protected getCheckboxCheckedState ( string $name, mixed $value, boolean $checked ) : boolean
$name string
$value mixed
$checked boolean
return boolean

getCheckedState() protected method

Get the check state for a checkable input.
protected getCheckedState ( string $type, string $name, mixed $value, boolean $checked ) : boolean
$type string
$name string
$value mixed
$checked boolean
return boolean

getControllerAction() protected method

Get the action for an "action" option.
protected getControllerAction ( array | string $options ) : string
$options array | string
return string

getIdAttribute() public method

Get the ID attribute for a field name.
public getIdAttribute ( string $name, array $attributes ) : string
$name string
$attributes array
return string

getMethod() protected method

Parse the form action method.
protected getMethod ( string $method ) : string
$method string
return string

getModelValueAttribute() protected method

Get the model value that should be assigned to the field.
protected getModelValueAttribute ( string $name ) : mixed
$name string
return mixed

getRadioCheckedState() protected method

Get the check state for a radio input.
protected getRadioCheckedState ( string $name, mixed $value, boolean $checked ) : boolean
$name string
$value mixed
$checked boolean
return boolean

getRouteAction() protected method

Get the action for a "route" option.
protected getRouteAction ( array | string $options ) : string
$options array | string
return string

getSelectOption() public method

Get the select option for the given value.
public getSelectOption ( string $display, string $value, string $selected ) : Illuminate\Support\HtmlString
$display string
$value string
$selected string
return Illuminate\Support\HtmlString

getSelectedValue() protected method

Determine if the value is selected.
protected getSelectedValue ( string $value, string $selected ) : null | string
$value string
$selected string
return null | string

getSessionStore() public method

Get the session store implementation.
public getSessionStore ( ) : Illuminate\Session\SessionInterface
return Illuminate\Session\SessionInterface $session

getUrlAction() protected method

Get the action for a "url" option.
protected getUrlAction ( array | string $options ) : string
$options array | string
return string

getValueAttribute() public method

Get the value that should be assigned to the field.
public getValueAttribute ( string $name, string $value = null ) : mixed
$name string
$value string
return mixed

hidden() public method

Create a hidden input field.
public hidden ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

image() public method

Create a HTML image input element.
public image ( string $url, string $name = null, array $attributes = [] ) : Illuminate\Support\HtmlString
$url string
$name string
$attributes array
return Illuminate\Support\HtmlString

input() public method

Create a form input field.
public input ( string $type, string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$type string
$name string
$value string
$options array
return Illuminate\Support\HtmlString

label() public method

Create a form label element.
public label ( string $name, string $value = null, array $options = [], boolean $escape_html = true ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
$escape_html boolean
return Illuminate\Support\HtmlString

macroCall() public method

public macroCall ( )

missingOldAndModel() protected method

Determine if old input or model input exists for a key.
protected missingOldAndModel ( string $name ) : boolean
$name string
return boolean

model() public method

Create a new model based form builder.
public model ( mixed $model, array $options = [] ) : Illuminate\Support\HtmlString
$model mixed
$options array
return Illuminate\Support\HtmlString

number() public method

Create a number input field.
public number ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

old() public method

Get a value from the session's old input.
public old ( string $name ) : mixed
$name string
return mixed

oldInputIsEmpty() public method

Determine if the old input is empty.
public oldInputIsEmpty ( ) : boolean
return boolean

open() public method

Open up a new HTML form.
public open ( array $options = [] ) : Illuminate\Support\HtmlString
$options array
return Illuminate\Support\HtmlString

option() protected method

Create a select element option.
protected option ( string $display, string $value, string $selected ) : Illuminate\Support\HtmlString
$display string
$value string
$selected string
return Illuminate\Support\HtmlString

optionGroup() protected method

Create an option group form element.
protected optionGroup ( array $list, string $label, string $selected ) : Illuminate\Support\HtmlString
$list array
$label string
$selected string
return Illuminate\Support\HtmlString

password() public method

Create a password input field.
public password ( string $name, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$options array
return Illuminate\Support\HtmlString

placeholderOption() protected method

Create a placeholder select element option.
protected placeholderOption ( $display, $selected ) : Illuminate\Support\HtmlString
$display
$selected
return Illuminate\Support\HtmlString

radio() public method

Create a radio button input field.
public radio ( string $name, mixed $value = null, boolean $checked = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value mixed
$checked boolean
$options array
return Illuminate\Support\HtmlString

reset() public method

Create a HTML reset input element.
public reset ( string $value, array $attributes = [] ) : Illuminate\Support\HtmlString
$value string
$attributes array
return Illuminate\Support\HtmlString

select() public method

Create a select box field.
public select ( string $name, array $list = [], string $selected = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$list array
$selected string
$options array
return Illuminate\Support\HtmlString

selectMonth() public method

Create a select month field.
public selectMonth ( string $name, string $selected = null, array $options = [], string $format = '%B' ) : Illuminate\Support\HtmlString
$name string
$selected string
$options array
$format string
return Illuminate\Support\HtmlString

selectRange() public method

Create a select range field.
public selectRange ( string $name, string $begin, string $end, string $selected = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$begin string
$end string
$selected string
$options array
return Illuminate\Support\HtmlString

selectYear() public method

Create a select year field.
public selectYear ( ) : mixed
return mixed

setModel() public method

Set the model instance on the form builder.
public setModel ( mixed $model ) : void
$model mixed
return void

setQuickTextAreaSize() protected method

Set the text area size using the quick "size" attribute.
protected setQuickTextAreaSize ( array $options ) : array
$options array
return array

setSessionStore() public method

Set the session store implementation.
public setSessionStore ( Illuminate\Session\SessionInterface $session )
$session Illuminate\Session\SessionInterface

setTextAreaSize() protected method

Set the text area size on the attributes.
protected setTextAreaSize ( array $options ) : array
$options array
return array

submit() public method

Create a submit button element.
public submit ( string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$value string
$options array
return Illuminate\Support\HtmlString

tel() public method

Create a tel input field.
public tel ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

text() public method

Create a text input field.
public text ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

textarea() public method

Create a textarea input field.
public textarea ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

time() public method

Create a time input field.
public time ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

toHtmlString() protected method

Transform the string to an Html serializable object
protected toHtmlString ( $html ) : Illuminate\Support\HtmlString
$html
return Illuminate\Support\HtmlString

token() public method

Generate a hidden field with the current CSRF token.
public token ( ) : string
return string

transformKey() protected method

Transform key from array to dot syntax.
protected transformKey ( string $key ) : mixed
$key string
return mixed

url() public method

Create a url input field.
public url ( string $name, string $value = null, array $options = [] ) : Illuminate\Support\HtmlString
$name string
$value string
$options array
return Illuminate\Support\HtmlString

Property Details

$csrfToken protected property

The CSRF token used by the form builder.
protected string $csrfToken
return string

$html protected property

The HTML builder instance.
protected HtmlBuilder,Collective\Html $html
return HtmlBuilder

$labels protected property

An array of label names we've created.
protected array $labels
return array

$model protected property

The current model instance for the form.
protected mixed $model
return mixed

$reserved protected property

The reserved form open attributes.
protected array $reserved
return array

$session protected property

The session store implementation.
protected SessionInterface,Illuminate\Session $session
return Illuminate\Session\SessionInterface

$skipValueTypes protected property

The types of inputs to not fill values on by default.
protected array $skipValueTypes
return array

$spoofedMethods protected property

The form methods that should be spoofed, in uppercase.
protected array $spoofedMethods
return array

$url protected property

The URL generator instance.
protected UrlGenerator,Illuminate\Contracts\Routing $url
return Illuminate\Contracts\Routing\UrlGenerator

$view protected property

The View factory instance.
protected Factory,Illuminate\Contracts\View $view
return Illuminate\Contracts\View\Factory