Form Class

Helper for creating forms with support for creating dynamic form objects.

package Fuel
category Core

 Methods

__construct()

__construct($fieldset, array $config) 

Parameters

$fieldset

$config

Magic method toString that will build this as a form

__toString() : string

Returns

string

Alias for $this->fieldset->add()

add($name, $label, array $attributes, array $rules) : \Fuel\Core\Fieldset_Field

Parameters

$name

string

$label

string

$attributes

array

$rules

array

Returns

Add a CSRF token and a validation rule to check it

add_csrf() 

Alias for $this->fieldset->add_model()

add_model(string | Object $class, array | Object $instance, string $method) : \Fuel\Core\Validation

Parameters

$class

stringObject

either a full classname (including full namespace) or object instance

$instance

arrayObject

array or object that has the exactly same named properties to populate the fields

$method

string

method name to call on model for field fetching

Returns

\Fuel\Core\Validationthis, to allow chaining

Alias for $this->fieldset->build()

build(mixed $action) : string

Parameters

$action

mixed

Returns

string

Build & template individual field

build_field(string | \Fuel\Core\Fieldset_Field $field) : string

deprecated until v1.2

Parameters

$field

string\Fuel\Core\Fieldset_Field

field instance or name of a field in this form's fieldset

Returns

string

Create a button

button(string | array $field, string $value, array $attributes) : string

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$value

string

$attributes

array

Returns

string

Create a checkbox

checkbox(string | array $field, string $value, mixed $checked, array $attributes) : string

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$value

string

$checked

mixed

either attributes (array) or bool/string to set checked status

$attributes

array

Returns

string

Create a form close tag

close() : string

Returns

string

Alias for $this->fieldset->field()

field(string | null $name, bool $flatten) : \Fuel\Core\Fieldset_Field | false

Parameters

$name

stringnull

field name or null to fetch an array of all

$flatten

bool

whether to get the fields array or flattened array

Returns

Returns the related fieldset

fieldset() : \Fuel\Core\Fieldset

Create a fieldset close tag

fieldset_close() : string

Returns

string

Create a fieldset open tag

fieldset_open(array $attributes, string $legend) : string

Parameters

$attributes

array

array with tag attribute settings

$legend

string

string for the fieldset legend

Returns

string

Create a file upload input field

file(string | array $field, array $attributes) : string

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$attributes

array

Returns

string

Get form attribute

get_attribute(string $key, mixed $default) : mixed

Parameters

$key

string

$default

mixed

Returns

mixed

Get a single or multiple config values by key

get_config(string | array $key, mixed $default) : mixed | array

Parameters

$key

stringarray

a single key or multiple in an array, empty to fetch all

$default

mixed

default output when config wasn't set

Returns

mixedarraya single config value or multiple in an array when $key input was an array

Create a form input

input(string | array $field, string $value, array $attributes) : string

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$value

string

$attributes

array

Returns

string

Create a label field

label(string | array $label, string $id, array $attributes) : string

Parameters

$label

stringarray

either fieldname or full attributes array (when array other params are ignored)

$id

string

$attributes

array

Returns

string

Create a form open tag

open(string | array $attributes, array $hidden) : string

Parameters

$attributes

stringarray

action string or array with more tag attribute settings

$hidden

array

Returns

string

Create a password input field

password(string | array $field, string $value, array $attributes) : string

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$value

string

$attributes

array

Returns

string

Alias for $this->fieldset->populate() for this fieldset

populate(array | object $input, bool $repopulate) : \Fuel\Core\Fieldset

Parameters

$input

arrayobject

$repopulate

bool

Returns

Prep Value

prep_value(string $value) : string

Prepares the value for display in the form

Parameters

$value

string

Returns

string

Create a radio button

radio(string | array $field, string $value, mixed $checked, array $attributes) : string

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$value

string

$checked

mixed

either attributes (array) or bool/string to set checked status

$attributes

array

Returns

string

Alias for $this->fieldset->repopulate() for this fieldset

repopulate() : \Fuel\Core\Fieldset_Field

Create a reset button

reset(string | array $field, string $value, array $attributes) : string

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$value

string

$attributes

array

Returns

string

Select

select(string | array $field, string $values, array $options, array $attributes) : string

Generates a html select element based on the given parameters

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$values

string

selected value(s)

$options

array

array of options and option groups

$attributes

array

Returns

string

Set form attribute

set_attribute(string $key, mixed $value) : \Form_Instance

Parameters

$key

string

$value

mixed

Returns

\Form_Instance

Sets a config value on the fieldset

set_config(string $config, mixed $value) : \Fuel\Core\Fieldset

Parameters

$config

string

$value

mixed

Returns

\Fuel\Core\Fieldsetthis, to allow chaining

Create a submit button

submit(string | array $field, string $value, array $attributes) : string

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$value

string

$attributes

array

Returns

string

Create a textarea field

textarea(string | array $field, string $value, array $attributes) : string

Parameters

$field

stringarray

either fieldname or full attributes array (when array other params are ignored)

$value

string

$attributes

array

Returns

string

Attr to String

attr_to_string(array $attr) : string

Wraps the global attributes function and does some form specific work

Parameters

$attr

array

Returns

string

 Properties

 

Valid types for input tags (including HTML5)

$_valid_inputs 

 

$fieldset

$fieldset : \Fuel\Core\Fieldset