FormBuilder
in package
Uses
Macroable
Form builder
Tags
Table of Contents
- $csrfToken : string
- The CSRF token used by the form builder.
- $html : HtmlBuilder
- The HTML builder instance.
- $labels : array<string|int, mixed>
- An array of label names we've created.
- $macros : array<string|int, mixed>
- The registered string macros.
- $model : mixed
- The current model instance for the form.
- $reserved : array<string|int, mixed>
- The reserved form open attributes.
- $reservedAjax : array<string|int, mixed>
- The reserved form open attributes.
- $session : Store
- The session store implementation.
- $sessionKey : string
- The session key used by the form builder.
- $skipValueTypes : array<string|int, mixed>
- The types of inputs to not fill values on by default.
- $spoofedMethods : array<string|int, mixed>
- The form methods that should be spoofed, in uppercase.
- $url : UrlGenerator
- The URL generator instance.
- __call() : mixed
- Dynamically handle calls to the class.
- __callStatic() : mixed
- Dynamically handle calls to the class.
- __construct() : void
- Create a new form builder instance.
- ajax() : string
- Helper for opening a form used for an AJAX call.
- button() : string
- Create a button element.
- checkbox() : string
- Create a checkbox input field.
- close() : string
- Close the current form.
- email() : string
- Create an e-mail input field.
- file() : string
- Create a file input field.
- getIdAttribute() : string
- Get the ID attribute for a field name.
- getSelectOption() : string
- Get the select option for the given value.
- getSessionKey() : string
- Returns the active session key, used fr deferred bindings.
- getSessionStore() : Store
- Get the session store implementation.
- getValueAttribute() : string
- Get the value that should be assigned to the field.
- hasMacro() : bool
- Checks if macro is registered.
- hidden() : string
- Create a hidden input field.
- image() : string
- Create a HTML image input element.
- input() : string
- Create a form input field.
- label() : string
- Create a form label element.
- macro() : void
- Register a custom macro.
- mixin() : void
- Mix another object into the class.
- model() : string
- Create a new model based form builder.
- old() : string
- Get a value from the session's old input.
- oldInputIsEmpty() : bool
- Determine if the old input is empty.
- open() : string
- Open up a new HTML form and includes a session key.
- password() : string
- Create a password input field.
- radio() : string
- Create a radio button input field.
- reset() : string
- Create a HTML reset input element.
- select() : string
- Create a select box field with empty option support.
- selectMonth() : string
- Create a select month field.
- selectRange() : string
- Create a select range field.
- selectYear() : string
- Create a select year field.
- sessionKey() : string
- Returns a hidden HTML input, supplying the session key value.
- setModel() : void
- Set the model instance on the form builder.
- setSessionStore() : $this
- Set the session store implementation.
- submit() : string
- Create a submit button element.
- text() : string
- Create a text input field.
- textarea() : string
- Create a textarea input field.
- token() : string
- Generate a hidden field with the current CSRF token.
- url() : string
- Create a url input field.
- value() : string
- Helper for getting form values. Tries to find the old value, then uses a postback/get value, then looks at the form model values.
- checkable() : string
- Create a checkable input field.
- formatLabel() : string
- Format the label value.
- getAction() : string
- Get the form action from the options.
- getAppendage() : string
- Get the form appendage for the given method.
- getCheckboxCheckedState() : bool
- Get the check state for a checkbox input.
- getCheckedState() : bool
- Get the check state for a checkable input.
- getControllerAction() : string
- Get the action for an "action" option.
- getMethod() : string
- Parse the form action method.
- getModelValueAttribute() : string
- Get the model value that should be assigned to the field.
- getRadioCheckedState() : bool
- Get the check state for a radio input.
- getRouteAction() : string
- Get the action for a "route" option.
- getSelectedValue() : string
- Determine if the value is selected.
- getUrlAction() : string
- Get the action for a "url" option.
- missingOldAndModel() : bool
- Determine if old input or model input exists for a key.
- option() : string
- Create a select element option.
- optionGroup() : string
- Create an option group form element.
- requestHandler() : string
- Returns a hidden HTML input, supplying the session key value.
- setQuickTextAreaSize() : array<string|int, mixed>
- Set the text area size using the quick "size" attribute.
- setTextAreaSize() : array<string|int, mixed>
- Set the text area size on the attributes.
- transformKey() : string
- Transform key from array to dot syntax.
Properties
$csrfToken
The CSRF token used by the form builder.
protected
string
$csrfToken
$html
The HTML builder instance.
protected
HtmlBuilder
$html
$labels
An array of label names we've created.
protected
array<string|int, mixed>
$labels
= []
$macros
The registered string macros.
protected
static array<string|int, mixed>
$macros
= []
$model
The current model instance for the form.
protected
mixed
$model
$reserved
The reserved form open attributes.
protected
array<string|int, mixed>
$reserved
= ['method', 'url', 'route', 'action', 'files', 'request', 'model', 'sessionKey']
$reservedAjax
The reserved form open attributes.
protected
array<string|int, mixed>
$reservedAjax
= ['request', 'success', 'error', 'complete', 'confirm', 'redirect', 'update', 'data', 'validate', 'flash']
$session
The session store implementation.
protected
Store
$session
$sessionKey
The session key used by the form builder.
protected
string
$sessionKey
$skipValueTypes
The types of inputs to not fill values on by default.
protected
array<string|int, mixed>
$skipValueTypes
= ['file', 'password', 'checkbox', 'radio']
$spoofedMethods
The form methods that should be spoofed, in uppercase.
protected
array<string|int, mixed>
$spoofedMethods
= ['DELETE', 'PATCH', 'PUT']
$url
The URL generator instance.
protected
UrlGenerator
$url
Methods
__call()
Dynamically handle calls to the class.
public
__call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__callStatic()
Dynamically handle calls to the class.
public
static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__construct()
Create a new form builder instance.
public
__construct(HtmlBuilder $html, UrlGenerator $url, string $csrfToken, string $sessionKey) : void
Parameters
- $html : HtmlBuilder
- $url : UrlGenerator
- $csrfToken : string
- $sessionKey : string
Return values
void —ajax()
Helper for opening a form used for an AJAX call.
public
ajax(string $handler[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $handler : string
-
Request handler name, eg: onUpdate
- $options : array<string|int, mixed> = []
Return values
string —button()
Create a button element.
public
button([string $value = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $value : string = null
- $options : array<string|int, mixed> = []
Return values
string —checkbox()
Create a checkbox input field.
public
checkbox(string $name[, mixed $value = 1 ][, bool $checked = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $value : mixed = 1
- $checked : bool = null
- $options : array<string|int, mixed> = []
Return values
string —close()
Close the current form.
public
close() : string
Return values
string —email()
Create an e-mail input field.
public
email(string $name[, string $value = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $value : string = null
- $options : array<string|int, mixed> = []
Return values
string —file()
Create a file input field.
public
file(string $name[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $options : array<string|int, mixed> = []
Return values
string —getIdAttribute()
Get the ID attribute for a field name.
public
getIdAttribute(string $name, array<string|int, mixed> $attributes) : string
Parameters
- $name : string
- $attributes : array<string|int, mixed>
Return values
string —getSelectOption()
Get the select option for the given value.
public
getSelectOption(string $display, string $value, string $selected) : string
Parameters
- $display : string
- $value : string
- $selected : string
Return values
string —getSessionKey()
Returns the active session key, used fr deferred bindings.
public
getSessionKey() : string
Return values
string —getSessionStore()
Get the session store implementation.
public
getSessionStore() : Store
Return values
Store —$session
getValueAttribute()
Get the value that should be assigned to the field.
public
getValueAttribute(string $name[, string $value = null ]) : string
Parameters
- $name : string
- $value : string = null
Return values
string —hasMacro()
Checks if macro is registered.
public
static hasMacro(string $name) : bool
Parameters
- $name : string
Return values
bool —hidden()
Create a hidden input field.
public
hidden(string $name[, string $value = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $value : string = null
- $options : array<string|int, mixed> = []
Return values
string —image()
Create a HTML image input element.
public
image(string $url[, string $name = null ][, array<string|int, mixed> $attributes = [] ]) : string
Parameters
- $url : string
- $name : string = null
- $attributes : array<string|int, mixed> = []
Return values
string —input()
Create a form input field.
public
input(string $type, string $name[, string $value = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $type : string
- $name : string
- $value : string = null
- $options : array<string|int, mixed> = []
Return values
string —label()
Create a form label element.
public
label(string $name[, string $value = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $value : string = null
- $options : array<string|int, mixed> = []
Return values
string —macro()
Register a custom macro.
public
static macro(string $name, object|callable $macro) : void
Parameters
- $name : string
- $macro : object|callable
Return values
void —mixin()
Mix another object into the class.
public
static mixin(object $mixin) : void
Parameters
- $mixin : object
Return values
void —model()
Create a new model based form builder.
public
model(mixed $model[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $model : mixed
- $options : array<string|int, mixed> = []
Return values
string —old()
Get a value from the session's old input.
public
old(string $name) : string
Parameters
- $name : string
Return values
string —oldInputIsEmpty()
Determine if the old input is empty.
public
oldInputIsEmpty() : bool
Return values
bool —open()
Open up a new HTML form and includes a session key.
public
open([array<string|int, mixed> $options = [] ]) : string
Parameters
- $options : array<string|int, mixed> = []
Return values
string —password()
Create a password input field.
public
password(string $name[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $options : array<string|int, mixed> = []
Return values
string —radio()
Create a radio button input field.
public
radio(string $name[, mixed $value = null ][, bool $checked = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $value : mixed = null
- $checked : bool = null
- $options : array<string|int, mixed> = []
Return values
string —reset()
Create a HTML reset input element.
public
reset(string $value[, array<string|int, mixed> $attributes = [] ]) : string
Parameters
- $value : string
- $attributes : array<string|int, mixed> = []
Return values
string —select()
Create a select box field with empty option support.
public
select(string $name[, array<string|int, mixed> $list = [] ][, string $selected = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $list : array<string|int, mixed> = []
- $selected : string = null
- $options : array<string|int, mixed> = []
Return values
string —selectMonth()
Create a select month field.
public
selectMonth(string $name[, string $selected = null ][, array<string|int, mixed> $options = [] ][, string $format = '%B' ]) : string
Parameters
- $name : string
- $selected : string = null
- $options : array<string|int, mixed> = []
- $format : string = '%B'
Return values
string —selectRange()
Create a select range field.
public
selectRange(string $name, string $begin, string $end[, string $selected = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $begin : string
- $end : string
- $selected : string = null
- $options : array<string|int, mixed> = []
Return values
string —selectYear()
Create a select year field.
public
selectYear() : string
Return values
string —sessionKey()
Returns a hidden HTML input, supplying the session key value.
public
sessionKey([mixed $sessionKey = null ]) : string
Parameters
- $sessionKey : mixed = null
Return values
string —setModel()
Set the model instance on the form builder.
public
setModel(mixed $model) : void
Parameters
- $model : mixed
Return values
void —setSessionStore()
Set the session store implementation.
public
setSessionStore(Store $session) : $this
Parameters
- $session : Store
Return values
$this —submit()
Create a submit button element.
public
submit([string $value = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $value : string = null
- $options : array<string|int, mixed> = []
Return values
string —text()
Create a text input field.
public
text(string $name[, string $value = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $value : string = null
- $options : array<string|int, mixed> = []
Return values
string —textarea()
Create a textarea input field.
public
textarea(string $name[, string $value = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $value : string = null
- $options : array<string|int, mixed> = []
Return values
string —token()
Generate a hidden field with the current CSRF token.
public
token() : string
Return values
string —url()
Create a url input field.
public
url(string $name[, string $value = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
- $value : string = null
- $options : array<string|int, mixed> = []
Return values
string —value()
Helper for getting form values. Tries to find the old value, then uses a postback/get value, then looks at the form model values.
public
value(string $name[, string $value = null ]) : string
Parameters
- $name : string
- $value : string = null
Return values
string —checkable()
Create a checkable input field.
protected
checkable(string $type, string $name, mixed $value, bool $checked, array<string|int, mixed> $options) : string
Parameters
- $type : string
- $name : string
- $value : mixed
- $checked : bool
- $options : array<string|int, mixed>
Return values
string —formatLabel()
Format the label value.
protected
formatLabel(string $name, string|null $value) : string
Parameters
- $name : string
- $value : string|null
Return values
string —getAction()
Get the form action from the options.
protected
getAction(array<string|int, mixed> $options) : string
Parameters
- $options : array<string|int, mixed>
Return values
string —getAppendage()
Get the form appendage for the given method.
protected
getAppendage(string $method) : string
Parameters
- $method : string
Return values
string —getCheckboxCheckedState()
Get the check state for a checkbox input.
protected
getCheckboxCheckedState(string $name, mixed $value, bool $checked) : bool
Parameters
- $name : string
- $value : mixed
- $checked : bool
Return values
bool —getCheckedState()
Get the check state for a checkable input.
protected
getCheckedState(string $type, string $name, mixed $value, bool $checked) : bool
Parameters
- $type : string
- $name : string
- $value : mixed
- $checked : bool
Return values
bool —getControllerAction()
Get the action for an "action" option.
protected
getControllerAction(array<string|int, mixed>|string $options) : string
Parameters
- $options : array<string|int, mixed>|string
Return values
string —getMethod()
Parse the form action method.
protected
getMethod(string $method) : string
Parameters
- $method : string
Return values
string —getModelValueAttribute()
Get the model value that should be assigned to the field.
protected
getModelValueAttribute(string $name) : string
Parameters
- $name : string
Return values
string —getRadioCheckedState()
Get the check state for a radio input.
protected
getRadioCheckedState(string $name, mixed $value, bool $checked) : bool
Parameters
- $name : string
- $value : mixed
- $checked : bool
Return values
bool —getRouteAction()
Get the action for a "route" option.
protected
getRouteAction(array<string|int, mixed>|string $options) : string
Parameters
- $options : array<string|int, mixed>|string
Return values
string —getSelectedValue()
Determine if the value is selected.
protected
getSelectedValue(string $value, string $selected) : string
Parameters
- $value : string
- $selected : string
Return values
string —getUrlAction()
Get the action for a "url" option.
protected
getUrlAction(array<string|int, mixed>|string $options) : string
Parameters
- $options : array<string|int, mixed>|string
Return values
string —missingOldAndModel()
Determine if old input or model input exists for a key.
protected
missingOldAndModel(string $name) : bool
Parameters
- $name : string
Return values
bool —option()
Create a select element option.
protected
option(string $display, string $value, string $selected) : string
Parameters
- $display : string
- $value : string
- $selected : string
Return values
string —optionGroup()
Create an option group form element.
protected
optionGroup(array<string|int, mixed> $list, string $label, string $selected) : string
Parameters
- $list : array<string|int, mixed>
- $label : string
- $selected : string
Return values
string —requestHandler()
Returns a hidden HTML input, supplying the session key value.
protected
requestHandler([mixed $name = null ]) : string
Parameters
- $name : mixed = null
Return values
string —setQuickTextAreaSize()
Set the text area size using the quick "size" attribute.
protected
setQuickTextAreaSize(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed>
Return values
array<string|int, mixed> —setTextAreaSize()
Set the text area size on the attributes.
protected
setTextAreaSize(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed>
Return values
array<string|int, mixed> —transformKey()
Transform key from array to dot syntax.
protected
transformKey(string $key) : string
Parameters
- $key : string