FormBuilder

Form builder

 class Winter\Storm\Html\FormBuilder

Traits

Properties

protected $csrfToken : string | null

The CSRF token used by the form builder.

protected $html : Winter\Storm\Html\HtmlBuilder

The HTML builder instance.

protected $labels : array

An array of label names we've created.

protected $model : object | array | null

The current model instance for the form.

protected $reserved : array

The reserved form open attributes.

protected $reservedAjax : array

The reserved form AJAX attributes.

protected $session : Illuminate\Session\Store | null

The session store implementation.

protected $sessionKey : string | null

The session key used by the form builder.

protected $skipValueTypes : array

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

protected $spoofedMethods : array

The form methods that should be spoofed, in uppercase.

protected $url : Illuminate\Routing\UrlGenerator

The URL generator instance.

Methods

public __construct (Winter\Storm\Html\HtmlBuilder $html, Illuminate\Routing\UrlGenerator $url, $csrfToken = null, $sessionKey = null)

Create a new form builder instance.

Parameters
Property Description
$html
Winter\Storm\Html\HtmlBuilder
$url
Illuminate\Routing\UrlGenerator
$csrfToken
mixed
$sessionKey
mixed
Returns
mixed

public ajax (string | array $handler, array $options = []) : string

Helper for opening a form used for an AJAX call.

Parameters
Property Description
$handler
string | array
$options
array
Returns
string

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

Create a button element.

Parameters
Property Description
$value
string
$options
array
Returns
string

public checkbox (string $name, string $value = "1", boolean $checked = false, array $options = []) : string

Create a checkbox input field.

Parameters
Property Description
$name
string
$value
string
$checked
boolean
$options
array
Returns
string

public close () : string

Close the current form.

Returns
string

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

Create an email input field.

Parameters
Property Description
$name
string
$value
mixed
$options
array
Returns
string

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

Create a file input field.

Parameters
Property Description
$name
string
$options
array
Returns
string

public getIdAttribute (string $name, array $attributes) : string | null

Get the ID attribute for a field name.

Parameters
Property Description
$name
string
$attributes
array
Returns
string | null

public getSelectOption (string | array $display, string $value, $selected = null) : string

Get the select option for the given value.

Parameters
Property Description
$display
string | array
$value
string
$selected
mixed
Returns
string

public getSessionKey () : string | null

Returns the active session key, used fr deferred bindings.

Returns
string | null

public getSessionStore () : Illuminate\Session\Store

Get the session store implementation.

Returns
Illuminate\Session\Store

$session

public getValueAttribute (string | null $name = null, string | array | int | null $value = null) : string | array | null

Get the value that should be assigned to the field.

Parameters
Property Description
$name
string | null
$value
string | array | int | null
Returns
string | array | null

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

Create a hidden input field.

Parameters
Property Description
$name
string
$value
mixed
$options
array
Returns
string

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

Create a HTML image input element.

Parameters
Property Description
$url
string
$name
string
$attributes
array
Returns
string

public input (string $type, string | null $name = null, string | null $value = null, array $options = []) : string

Create a form input field.

Parameters
Property Description
$type
string
$name
string | null
$value
string | null
$options
array
Returns
string

public label (string $name, string $value = "", array $options = []) : string

Create a form label element.

Parameters
Property Description
$name
string
$value
string
$options
array
Returns
string

public model (object | array $model, array $options = []) : string

Create a new model based form builder.

Parameters
Property Description
$model
object | array
$options
array
Returns
string

public old (string $name) : string | array | null

Get a value from the session's old input.

Parameters
Property Description
$name
string
Returns
string | array | null

public oldInputIsEmpty () : bool

Determine if the old input is empty.

Returns
bool

public open (array $options = []) : string

Open up a new HTML form and includes a session key.

Parameters
Property Description
$options
array
Returns
string

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

Create a password input field.

Parameters
Property Description
$name
string
$options
array
Returns
string

public radio (string $name, $value = null, boolean $checked = false, array $options = []) : string

Create a radio button input field.

Parameters
Property Description
$name
string
$value
mixed
$checked
boolean
$options
array
Returns
string

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

Create a HTML reset input element.

Parameters
Property Description
$value
string
$attributes
array
Returns
string

public select (string $name, array $list = [], $selected = null, array $options = []) : string

Create a select box field with empty option support.

Parameters
Property Description
$name
string
$list
array
$selected
mixed
$options
array
Returns
string

public selectMonth (string $name, $selected = null, array $options = [], string $format = "%B") : string

Create a select month field.

Parameters
Property Description
$name
string
$selected
mixed
$options
array
$format
string
Returns
string

public selectRange (string $name, string | integer | float $begin, string | integer | float $end, $selected = null, array $options = []) : string

Create a select range field.

Parameters
Property Description
$name
string
$begin
string | integer | float
$end
string | integer | float
$selected
mixed
$options
array
Returns
string

public selectYear (string $name, integer $begin = 1900, $end = null, $selected = null, array $options = []) : string

Create a select year field.

Parameters
Property Description
$name
string
$begin
integer
$end
mixed
$selected
mixed
$options
array
Returns
string

public sessionKey ($sessionKey = null) : string

Returns a hidden HTML input, supplying the session key value.

Parameters
Property Description
$sessionKey
mixed
Returns
string

public setModel (object | array | null $model) : void

Set the model instance on the form builder.

Parameters
Property Description
$model
object | array | null
Returns
void

public setSessionStore (Illuminate\Session\Store $session) : $this

Set the session store implementation.

Parameters
Property Description
$session
Illuminate\Session\Store
Returns
$this

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

Create a submit button element.

Parameters
Property Description
$value
string
$options
array
Returns
string

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

Create a text input field.

Parameters
Property Description
$name
string
$value
mixed
$options
array
Returns
string

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

Create a textarea input field.

Parameters
Property Description
$name
string
$value
mixed
$options
array
Returns
string

public token () : string

Generate a hidden field with the current CSRF token.

Returns
string

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

Create a URL input field.

Parameters
Property Description
$name
string
$value
mixed
$options
array
Returns
string

public value (string $name, string $value = null) : 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.

Parameters
Property Description
$name
string
$value
string
Returns
string

protected checkable (string $type, string $name, string $value, boolean $checked = false, array $options = []) : string

Create a checkable input field.

Parameters
Property Description
$type
string
$name
string
$value
string
$checked
boolean
$options
array
Returns
string

protected formatLabel (string $name, string $value = "") : string

Format the label value.

Parameters
Property Description
$name
string
$value
string
Returns
string

protected getAction (array $options) : string

Get the form action from the options.

Parameters
Property Description
$options
array
Returns
string

protected getAppendage (string $method) : string

Get the form appendage for the given method.

Parameters
Property Description
$method
string
Returns
string

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

Get the check state for a checkbox input.

Parameters
Property Description
$name
string
$value
mixed
$checked
bool
Returns
bool

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

Get the check state for a checkable input.

Parameters
Property Description
$type
string
$name
string
$value
mixed
$checked
bool
Returns
bool

protected getControllerAction (array | string $options) : string

Get the action for an "action" option.

Parameters
Property Description
$options
array | string
Returns
string

protected getMethod (string $method) : string

Parse the form action method.

Parameters
Property Description
$method
string
Returns
string

protected getModelValueAttribute (string $name) : string | array | null

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

Parameters
Property Description
$name
string
Returns
string | array | null

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

Get the check state for a radio input.

Parameters
Property Description
$name
string
$value
mixed
$checked
bool
Returns
bool

protected getRouteAction (array | string $options) : string

Get the action for a "route" option.

Parameters
Property Description
$options
array | string
Returns
string

protected getSelectedValue (string $value, string | array | null $selected) : string | null

Determine if the value is selected.

Parameters
Property Description
$value
string
$selected
string | array | null
Returns
string | null

protected getUrlAction (array | string $options) : string

Get the action for a "url" option.

Parameters
Property Description
$options
array | string
Returns
string

protected missingOldAndModel (string $name) : bool

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

Parameters
Property Description
$name
string
Returns
bool

protected option (string $display, string $value, $selected = null) : string

Create a select element option.

Parameters
Property Description
$display
string
$value
string
$selected
mixed
Returns
string

protected optionGroup (array $list, string $label, $selected = null) : string

Create an option group form element.

Parameters
Property Description
$list
array
$label
string
$selected
mixed
Returns
string

protected requestHandler ($name = null) : string

Returns a hidden HTML input, supplying the session key value.

Parameters
Property Description
$name
mixed
Returns
string

protected setQuickTextAreaSize (array $options) : array

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

Parameters
Property Description
$options
array
Returns
array

protected setTextAreaSize (array $options) : array

Set the text area size on the attributes.

Parameters
Property Description
$options
array
Returns
array

protected transformKey (string $key) : string

Transform key from array to dot syntax.

Parameters
Property Description
$key
string
Returns
string
Copyright © 2024 Winter CMS