class FormBuilder

Traits

Macroable

Properties

static protected array $components

The registered components.

from  Componentable
protected HtmlBuilder $html

The HTML builder instance.

protected UrlGenerator $url

The URL generator instance.

protected Factory $view

The View factory instance.

protected string $csrfToken

The CSRF token used by the form builder.

protected Session $session

The session store implementation.

protected mixed $model

The current model instance for the form.

protected array $labels

An array of label names we've created.

protected $request
protected array $reserved

The reserved form open attributes.

protected array $spoofedMethods

The form methods that should be spoofed, in uppercase.

protected array $skipValueTypes

The types of inputs to not fill values on by default.

protected null $type

Input Type.

Methods

static void
component($name, $view, array $signature)

Register a custom component.

static bool
hasComponent($name)

Check if a component is registered.

HtmlString
renderComponent($name, array $arguments)

Render a custom component.

array
getComponentData(array $signature, array $arguments)

Prepare the component data, while respecting provided defaults.

View|mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(HtmlBuilder $html, UrlGenerator $url, Factory $view, string $csrfToken, Request $request = null)

Create a new form builder instance.

HtmlString
open(array $options = [])

Open up a new HTML form.

HtmlString
model(mixed $model, array $options = [])

Create a new model based form builder.

void
setModel(mixed $model)

Set the model instance on the form builder.

string
close()

Close the current form.

string
token()

Generate a hidden field with the current CSRF token.

HtmlString
label(string $name, string $value = null, array $options = [], bool $escape_html = true)

Create a form label element.

string
formatLabel(string $name, string|null $value)

Format the label value.

HtmlString
input(string $type, string $name, string $value = null, array $options = [])

Create a form input field.

HtmlString
text(string $name, string $value = null, array $options = [])

Create a text input field.

HtmlString
password(string $name, array $options = [])

Create a password input field.

HtmlString
hidden(string $name, string $value = null, array $options = [])

Create a hidden input field.

HtmlString
search(string $name, string $value = null, array $options = [])

Create a search input field.

HtmlString
email(string $name, string $value = null, array $options = [])

Create an e-mail input field.

HtmlString
tel(string $name, string $value = null, array $options = [])

Create a tel input field.

HtmlString
number(string $name, string $value = null, array $options = [])

Create a number input field.

HtmlString
date(string $name, string $value = null, array $options = [])

Create a date input field.

HtmlString
datetime(string $name, string $value = null, array $options = [])

Create a datetime input field.

HtmlString
datetimeLocal(string $name, string $value = null, array $options = [])

Create a datetime-local input field.

HtmlString
time(string $name, string $value = null, array $options = [])

Create a time input field.

HtmlString
url(string $name, string $value = null, array $options = [])

Create a url input field.

HtmlString
file(string $name, array $options = [])

Create a file input field.

HtmlString
textarea(string $name, string $value = null, array $options = [])

Create a textarea input field.

array
setTextAreaSize(array $options)

Set the text area size on the attributes.

array
setQuickTextAreaSize(array $options)

Set the text area size using the quick "size" attribute.

HtmlString
select(string $name, array $list = [], string $selected = null, array $selectAttributes = [], array $optionsAttributes = [])

Create a select box field.

HtmlString
selectRange(string $name, string $begin, string $end, string $selected = null, array $options = [])

Create a select range field.

mixed
selectYear()

Create a select year field.

HtmlString
selectMonth(string $name, string $selected = null, array $options = [], string $format = '%B')

Create a select month field.

HtmlString
getSelectOption(string $display, string $value, string $selected, array $attributes = [])

Get the select option for the given value.

HtmlString
optionGroup(array $list, string $label, string $selected, array $attributes = [])

Create an option group form element.

HtmlString
option(string $display, string $value, string $selected, array $attributes = [])

Create a select element option.

HtmlString
placeholderOption($display, $selected)

Create a placeholder select element option.

null|string
getSelectedValue(string $value, string $selected)

Determine if the value is selected.

HtmlString
checkbox(string $name, mixed $value = 1, bool $checked = null, array $options = [])

Create a checkbox input field.

HtmlString
radio(string $name, mixed $value = null, bool $checked = null, array $options = [])

Create a radio button input field.

HtmlString
checkable(string $type, string $name, mixed $value, bool $checked, array $options)

Create a checkable input field.

bool
getCheckedState(string $type, string $name, mixed $value, bool $checked)

Get the check state for a checkable input.

bool
getCheckboxCheckedState(string $name, mixed $value, bool $checked)

Get the check state for a checkbox input.

bool
getRadioCheckedState(string $name, mixed $value, bool $checked)

Get the check state for a radio input.

bool
missingOldAndModel(string $name)

Determine if old input or model input exists for a key.

HtmlString
reset(string $value, array $attributes = [])

Create a HTML reset input element.

HtmlString
image(string $url, string $name = null, array $attributes = [])

Create a HTML image input element.

HtmlString
color(string $name, string $value = null, array $options = [])

Create a color input field.

HtmlString
submit(string $value = null, array $options = [])

Create a submit button element.

HtmlString
button(string $value = null, array $options = [])

Create a button element.

string
getMethod(string $method)

Parse the form action method.

string
getAction(array $options)

Get the form action from the options.

string
getUrlAction(array|string $options)

Get the action for a "url" option.

string
getRouteAction(array|string $options)

Get the action for a "route" option.

string
getControllerAction(array|string $options)

Get the action for an "action" option.

string
getAppendage(string $method)

Get the form appendage for the given method.

string
getIdAttribute(string $name, array $attributes)

Get the ID attribute for a field name.

mixed
getValueAttribute(string $name, string $value = null)

Get the value that should be assigned to the field.

array|null|string
request($name)

Get value from current Request

mixed
getModelValueAttribute(string $name)

Get the model value that should be assigned to the field.

mixed
old(string $name)

Get a value from the session's old input.

bool
oldInputIsEmpty()

Determine if the old input is empty.

mixed
transformKey(string $key)

Transform key from array to dot syntax.

HtmlString
toHtmlString($html)

Transform the string to an Html serializable object

Session
getSessionStore()

Get the session store implementation.

$this
setSessionStore(Session $session)

Set the session store implementation.

Details

in Componentable at line 26
static void component($name, $view, array $signature)

Register a custom component.

Parameters

$name
$view
array $signature

Return Value

void

in Componentable at line 38
static bool hasComponent($name)

Check if a component is registered.

Parameters

$name

Return Value

bool

in Componentable at line 51
protected HtmlString renderComponent($name, array $arguments)

Render a custom component.

Parameters

$name
array $arguments

Return Value

HtmlString

in Componentable at line 69
protected array getComponentData(array $signature, array $arguments)

Prepare the component data, while respecting provided defaults.

Parameters

array $signature
array $arguments

Return Value

array

at line 1307
View|mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

View|mixed

Exceptions

BadMethodCallException

at line 112
__construct(HtmlBuilder $html, UrlGenerator $url, Factory $view, string $csrfToken, Request $request = null)

Create a new form builder instance.

Parameters

HtmlBuilder $html
UrlGenerator $url
Factory $view
string $csrfToken
Request $request

at line 128
HtmlString open(array $options = [])

Open up a new HTML form.

Parameters

array $options

Return Value

HtmlString

at line 175
HtmlString model(mixed $model, array $options = [])

Create a new model based form builder.

Parameters

mixed $model
array $options

Return Value

HtmlString

at line 189
void setModel(mixed $model)

Set the model instance on the form builder.

Parameters

mixed $model

Return Value

void

at line 199
string close()

Close the current form.

Return Value

string

at line 213
string token()

Generate a hidden field with the current CSRF token.

Return Value

string

at line 230
HtmlString label(string $name, string $value = null, array $options = [], bool $escape_html = true)

Create a form label element.

Parameters

string $name
string $value
array $options
bool $escape_html

Return Value

HtmlString

at line 253
protected string formatLabel(string $name, string|null $value)

Format the label value.

Parameters

string $name
string|null $value

Return Value

string

at line 268
HtmlString input(string $type, string $name, string $value = null, array $options = [])

Create a form input field.

Parameters

string $type
string $name
string $value
array $options

Return Value

HtmlString

at line 304
HtmlString text(string $name, string $value = null, array $options = [])

Create a text input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 317
HtmlString password(string $name, array $options = [])

Create a password input field.

Parameters

string $name
array $options

Return Value

HtmlString

at line 331
HtmlString hidden(string $name, string $value = null, array $options = [])

Create a hidden input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

Create a search input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 359
HtmlString email(string $name, string $value = null, array $options = [])

Create an e-mail input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 373
HtmlString tel(string $name, string $value = null, array $options = [])

Create a tel input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 387
HtmlString number(string $name, string $value = null, array $options = [])

Create a number input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 401
HtmlString date(string $name, string $value = null, array $options = [])

Create a date input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 419
HtmlString datetime(string $name, string $value = null, array $options = [])

Create a datetime input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 437
HtmlString datetimeLocal(string $name, string $value = null, array $options = [])

Create a datetime-local input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 455
HtmlString time(string $name, string $value = null, array $options = [])

Create a time input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 469
HtmlString url(string $name, string $value = null, array $options = [])

Create a url input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 482
HtmlString file(string $name, array $options = [])

Create a file input field.

Parameters

string $name
array $options

Return Value

HtmlString

at line 496
HtmlString textarea(string $name, string $value = null, array $options = [])

Create a textarea input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 530
protected array setTextAreaSize(array $options)

Set the text area size on the attributes.

Parameters

array $options

Return Value

array

at line 553
protected array setQuickTextAreaSize(array $options)

Set the text area size using the quick "size" attribute.

Parameters

array $options

Return Value

array

at line 571
HtmlString select(string $name, array $list = [], string $selected = null, array $selectAttributes = [], array $optionsAttributes = [])

Create a select box field.

Parameters

string $name
array $list
string $selected
array $selectAttributes
array $optionsAttributes

Return Value

HtmlString

at line 627
HtmlString selectRange(string $name, string $begin, string $end, string $selected = null, array $options = [])

Create a select range field.

Parameters

string $name
string $begin
string $end
string $selected
array $options

Return Value

HtmlString

at line 639
mixed selectYear()

Create a select year field.

Return Value

mixed

at line 654
HtmlString selectMonth(string $name, string $selected = null, array $options = [], string $format = '%B')

Create a select month field.

Parameters

string $name
string $selected
array $options
string $format

Return Value

HtmlString

at line 675
HtmlString getSelectOption(string $display, string $value, string $selected, array $attributes = [])

Get the select option for the given value.

Parameters

string $display
string $value
string $selected
array $attributes

Return Value

HtmlString

at line 694
protected HtmlString optionGroup(array $list, string $label, string $selected, array $attributes = [])

Create an option group form element.

Parameters

array $list
string $label
string $selected
array $attributes

Return Value

HtmlString

at line 715
protected HtmlString option(string $display, string $value, string $selected, array $attributes = [])

Create a select element option.

Parameters

string $display
string $value
string $selected
array $attributes

Return Value

HtmlString

at line 732
protected HtmlString placeholderOption($display, $selected)

Create a placeholder select element option.

Parameters

$display
$selected

Return Value

HtmlString

at line 752
protected null|string getSelectedValue(string $value, string $selected)

Determine if the value is selected.

Parameters

string $value
string $selected

Return Value

null|string

at line 774
HtmlString checkbox(string $name, mixed $value = 1, bool $checked = null, array $options = [])

Create a checkbox input field.

Parameters

string $name
mixed $value
bool $checked
array $options

Return Value

HtmlString

at line 789
HtmlString radio(string $name, mixed $value = null, bool $checked = null, array $options = [])

Create a radio button input field.

Parameters

string $name
mixed $value
bool $checked
array $options

Return Value

HtmlString

at line 809
protected HtmlString checkable(string $type, string $name, mixed $value, bool $checked, array $options)

Create a checkable input field.

Parameters

string $type
string $name
mixed $value
bool $checked
array $options

Return Value

HtmlString

at line 832
protected bool getCheckedState(string $type, string $name, mixed $value, bool $checked)

Get the check state for a checkable input.

Parameters

string $type
string $name
mixed $value
bool $checked

Return Value

bool

at line 855
protected bool getCheckboxCheckedState(string $name, mixed $value, bool $checked)

Get the check state for a checkbox input.

Parameters

string $name
mixed $value
bool $checked

Return Value

bool

at line 889
protected bool getRadioCheckedState(string $name, mixed $value, bool $checked)

Get the check state for a radio input.

Parameters

string $name
mixed $value
bool $checked

Return Value

bool

at line 907
protected bool missingOldAndModel(string $name)

Determine if old input or model input exists for a key.

Parameters

string $name

Return Value

bool

at line 920
HtmlString reset(string $value, array $attributes = [])

Create a HTML reset input element.

Parameters

string $value
array $attributes

Return Value

HtmlString

at line 934
HtmlString image(string $url, string $name = null, array $attributes = [])

Create a HTML image input element.

Parameters

string $url
string $name
array $attributes

Return Value

HtmlString

at line 950
HtmlString color(string $name, string $value = null, array $options = [])

Create a color input field.

Parameters

string $name
string $value
array $options

Return Value

HtmlString

at line 963
HtmlString submit(string $value = null, array $options = [])

Create a submit button element.

Parameters

string $value
array $options

Return Value

HtmlString

at line 976
HtmlString button(string $value = null, array $options = [])

Create a button element.

Parameters

string $value
array $options

Return Value

HtmlString

at line 992
protected string getMethod(string $method)

Parse the form action method.

Parameters

string $method

Return Value

string

at line 1006
protected string getAction(array $options)

Get the form action from the options.

Parameters

array $options

Return Value

string

at line 1036
protected string getUrlAction(array|string $options)

Get the action for a "url" option.

Parameters

array|string $options

Return Value

string

at line 1052
protected string getRouteAction(array|string $options)

Get the action for a "route" option.

Parameters

array|string $options

Return Value

string

at line 1068
protected string getControllerAction(array|string $options)

Get the action for an "action" option.

Parameters

array|string $options

Return Value

string

at line 1084
protected string getAppendage(string $method)

Get the form appendage for the given method.

Parameters

string $method

Return Value

string

at line 1113
string getIdAttribute(string $name, array $attributes)

Get the ID attribute for a field name.

Parameters

string $name
array $attributes

Return Value

string

at line 1132
mixed getValueAttribute(string $name, string $value = null)

Get the value that should be assigned to the field.

Parameters

string $name
string $value

Return Value

mixed

at line 1179
protected array|null|string request($name)

Get value from current Request

Parameters

$name

Return Value

array|null|string

at line 1195
protected mixed getModelValueAttribute(string $name)

Get the model value that should be assigned to the field.

Parameters

string $name

Return Value

mixed

at line 1213
mixed old(string $name)

Get a value from the session's old input.

Parameters

string $name

Return Value

mixed

at line 1244
bool oldInputIsEmpty()

Determine if the old input is empty.

Return Value

bool

at line 1256
protected mixed transformKey(string $key)

Transform key from array to dot syntax.

Parameters

string $key

Return Value

mixed

at line 1268
protected HtmlString toHtmlString($html)

Transform the string to an Html serializable object

Parameters

$html

Return Value

HtmlString

at line 1278
Session getSessionStore()

Get the session store implementation.

Return Value

Session $session

at line 1290
$this setSessionStore(Session $session)

Set the session store implementation.

Parameters

Session $session

Return Value

$this