class FormBuilder (View source)

Traits

Properties

static protected array $macros The registered string macros. from MacroableTrait
protected HtmlBuilder $html The HTML builder instance.
protected UrlGenerator $url The URL generator instance.
protected string $csrfToken The CSRF token used by the form builder.
protected Store $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 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.

Methods

static void
macro(string $name, callable $macro)

Register a custom macro.

static boolean
hasMacro(string $name)

Checks if macro is registered

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

void
__construct(HtmlBuilder $html, UrlGenerator $url, $csrfToken)

Create a new form builder instance.

string
open(array $options = array())

Open up a new HTML form.

string
model(mixed $model, array $options = array())

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.

string
label(string $name, string $value = null, array $options = array())

Create a form label element.

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

Format the label value.

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

Create a form input field.

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

Create a text input field.

string
password(string $name, array $options = array())

Create a password input field.

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

Create a hidden input field.

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

Create an e-mail input field.

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

Create a url input field.

string
file(string $name, array $options = array())

Create a file input field.

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

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.

string
number(string $name, string|null $value = null, array $options = array())

Create a number input field.

string
select(string $name, array $list = array(), string $selected = null, array $options = array())

Create a select box field.

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

Create a select range field.

string
selectYear()

Create a select year field.

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

Create a select month field.

string
getSelectOption(string $display, string $value, string $selected)

Get the select option for the given value.

string
optionGroup(array $list, string $label, string $selected)

Create an option group form element.

string
option(string $display, string $value, string $selected)

Create a select element option.

string
getSelectedValue(string $value, string $selected)

Determine if the value is selected.

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

Create a checkbox input field.

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

Create a radio button input field.

string
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.

string
reset(string $value, array $attributes = array())

Create a HTML reset input element.

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

Create a HTML image input element.

string
submit(string $value = null, array $options = array())

Create a submit button element.

string
button(string $value = null, array $options = array())

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.

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

Get the value that should be assigned to the field.

string
getModelValueAttribute(string $name)

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

string
old(string $name)

Get a value from the session's old input.

bool
oldInputIsEmpty()

Determine if the old input is empty.

string
transformKey(string $key)

Transform key from array to dot syntax.

getSessionStore()

Get the session store implementation.

$this
setSessionStore(Store $session)

Set the session store implementation.

Details

static void macro(string $name, callable $macro)

Register a custom macro.

Parameters

string $name
callable $macro

Return Value

void

static boolean hasMacro(string $name)

Checks if macro is registered

Parameters

string $name

Return Value

boolean

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(HtmlBuilder $html, UrlGenerator $url, $csrfToken)

Create a new form builder instance.

Parameters

HtmlBuilder $html
UrlGenerator $url
$csrfToken

Return Value

void

string open(array $options = array())

Open up a new HTML form.

Parameters

array $options

Return Value

string

string model(mixed $model, array $options = array())

Create a new model based form builder.

Parameters

mixed $model
array $options

Return Value

string

void setModel(mixed $model)

Set the model instance on the form builder.

Parameters

mixed $model

Return Value

void

string close()

Close the current form.

Return Value

string

string token()

Generate a hidden field with the current CSRF token.

Return Value

string

string label(string $name, string $value = null, array $options = array())

Create a form label element.

Parameters

string $name
string $value
array $options

Return Value

string

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

Format the label value.

Parameters

string $name
string|null $value

Return Value

string

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

Create a form input field.

Parameters

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

Return Value

string

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

Create a text input field.

Parameters

string $name
string $value
array $options

Return Value

string

string password(string $name, array $options = array())

Create a password input field.

Parameters

string $name
array $options

Return Value

string

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

Create a hidden input field.

Parameters

string $name
string $value
array $options

Return Value

string

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

Create an e-mail input field.

Parameters

string $name
string $value
array $options

Return Value

string

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

Create a url input field.

Parameters

string $name
string $value
array $options

Return Value

string

string file(string $name, array $options = array())

Create a file input field.

Parameters

string $name
array $options

Return Value

string

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

Create a textarea input field.

Parameters

string $name
string $value
array $options

Return Value

string

protected array setTextAreaSize(array $options)

Set the text area size on the attributes.

Parameters

array $options

Return Value

array

protected array setQuickTextAreaSize(array $options)

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

Parameters

array $options

Return Value

array

string number(string $name, string|null $value = null, array $options = array())

Create a number input field.

Parameters

string $name
string|null $value
array $options

Return Value

string

string select(string $name, array $list = array(), string $selected = null, array $options = array())

Create a select box field.

Parameters

string $name
array $list
string $selected
array $options

Return Value

string

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

Create a select range field.

Parameters

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

Return Value

string

string selectYear()

Create a select year field.

Return Value

string

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

Create a select month field.

Parameters

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

Return Value

string

string getSelectOption(string $display, string $value, string $selected)

Get the select option for the given value.

Parameters

string $display
string $value
string $selected

Return Value

string

protected string optionGroup(array $list, string $label, string $selected)

Create an option group form element.

Parameters

array $list
string $label
string $selected

Return Value

string

protected string option(string $display, string $value, string $selected)

Create a select element option.

Parameters

string $display
string $value
string $selected

Return Value

string

protected string getSelectedValue(string $value, string $selected)

Determine if the value is selected.

Parameters

string $value
string $selected

Return Value

string

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

Create a checkbox input field.

Parameters

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

Return Value

string

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

Create a radio button input field.

Parameters

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

Return Value

string

protected string 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

string

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

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

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

protected bool missingOldAndModel(string $name)

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

Parameters

string $name

Return Value

bool

string reset(string $value, array $attributes = array())

Create a HTML reset input element.

Parameters

string $value
array $attributes

Return Value

string

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

Create a HTML image input element.

Parameters

string $url
string $name
array $attributes

Return Value

string

string submit(string $value = null, array $options = array())

Create a submit button element.

Parameters

string $value
array $options

Return Value

string

string button(string $value = null, array $options = array())

Create a button element.

Parameters

string $value
array $options

Return Value

string

protected string getMethod(string $method)

Parse the form action method.

Parameters

string $method

Return Value

string

protected string getAction(array $options)

Get the form action from the options.

Parameters

array $options

Return Value

string

protected string getUrlAction(array|string $options)

Get the action for a "url" option.

Parameters

array|string $options

Return Value

string

protected string getRouteAction(array|string $options)

Get the action for a "route" option.

Parameters

array|string $options

Return Value

string

protected string getControllerAction(array|string $options)

Get the action for an "action" option.

Parameters

array|string $options

Return Value

string

protected string getAppendage(string $method)

Get the form appendage for the given method.

Parameters

string $method

Return Value

string

string getIdAttribute(string $name, array $attributes)

Get the ID attribute for a field name.

Parameters

string $name
array $attributes

Return Value

string

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

Get the value that should be assigned to the field.

Parameters

string $name
string $value

Return Value

string

protected string getModelValueAttribute(string $name)

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

Parameters

string $name

Return Value

string

string old(string $name)

Get a value from the session's old input.

Parameters

string $name

Return Value

string

bool oldInputIsEmpty()

Determine if the old input is empty.

Return Value

bool

protected string transformKey(string $key)

Transform key from array to dot syntax.

Parameters

string $key

Return Value

string

Store getSessionStore()

Get the session store implementation.

Return Value

Store $session

$this setSessionStore(Store $session)

Set the session store implementation.

Parameters

Store $session

Return Value

$this