Fieldset Class

Define a set of fields that can be used to generate a form or to validate input.

package Fuel
category Core

 Methods

Constructor

__construct(string $name, string $label, array $attributes, array $rules, \Fuel\Core\Fieldset $fieldset) 

Parameters

$name

string

$label

string

$attributes

array

$rules

array

Exceptions

\RuntimeException

Magic get method to allow getting class properties but still having them protected to disallow writing.

__get($property) : mixed

Parameters

$property

Returns

mixed

Build the field

__toString() : string

Returns

string

Alias for $this->fieldset->add() to allow chaining

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

Parameters

$name

$label

$attributes

$rules

Returns

Alias for $this->fieldset->add_after() to allow chaining

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

Parameters

$name

$label

$attributes

$rules

$fieldname

Returns

Alias for $this->fieldset->add_before() to allow chaining

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

Parameters

$name

$label

$attributes

$rules

$fieldname

Returns

Add a validation rule any further arguements after the callback will be used as arguements for the callback

add_rule(string | Callback $callback) : \Fuel\Core\Fieldset_Field

Parameters

$callback

stringCallback

either a validation rule or full callback

Returns

\Fuel\Core\Fieldset_Fieldthis, to allow chaining

Build the field

build() : string

Returns

string

Delete a validation rule

delete_rule(string | Callback $callback, bool $set_attr) : \Fuel\Core\Fieldset_Field

Parameters

$callback

stringCallback

either a validation rule or full callback

$set_attr

bool

whether to also reset related attributes

Returns

\Fuel\Core\Fieldset_Fieldthis, to allow chaining

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

error() : \Fuel\Core\Validation_Error

Return the parent Fieldset object

fieldset() : \Fuel\Core\Fieldset

Get a single or multiple attributes by key

get_attribute(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 attribute wasn't set

Returns

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

Check if a rule has an error message overwrite

get_error_message(string $rule) : null | string

Parameters

$rule

string

Returns

nullstring

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

input() : mixed

Returns

mixed

Sets an attribute on the field

set_attribute($attr, mixed $value) : \Fuel\Core\Fieldset_Field

Parameters

$attr

string

$value

mixed

new value or null to unset

Returns

\Fuel\Core\Fieldset_Fieldthis, to allow chaining

Change the field description

set_description(string $description) : \Fuel\Core\Fieldset_Field

Parameters

$description

string

Returns

\Fuel\Core\Fieldset_Fieldthis, to allow chaining

Overwrite a default error message

set_error_message(string $rule, string $msg) : \Fuel\Core\Fieldset_Field

Parameters

$rule

string

$msg

string

Returns

set_fieldset()

set_fieldset(\Fuel\Core\Fieldset $fieldset) : \Fuel\Core\Fieldset_Field

Parameters

$fieldset

\Fuel\Core\Fieldset

Fieldset to assign the field to

Exceptions

\RuntimeException

Returns

Change the field label

set_label(string $label) : \Fuel\Core\Fieldset_Field

Parameters

$label

string

Returns

\Fuel\Core\Fieldset_Fieldthis, to allow chaining

Add an option value with label

set_options(string | array $value, $label, bool $replace_options) : \Fuel\Core\Fieldset_Field

Parameters

$value

stringarray

one option value, or multiple value=>label pairs in an array

$label

string

$replace_options

bool

Whether or not to replace the current options

Returns

\Fuel\Core\Fieldset_Fieldthis, to allow chaining

Template the output

set_template(string $template) : \Fuel\Core\Fieldset_Field

Parameters

$template

string

Returns

\Fuel\Core\Fieldset_Fieldthis, to allow chaining

Change the field type for form generation

set_type(string $type) : \Fuel\Core\Fieldset_Field

Parameters

$type

string

Returns

\Fuel\Core\Fieldset_Fieldthis, to allow chaining

Change the field's current or default value

set_value(string $value, bool $repopulate) : \Fuel\Core\Fieldset_Field

Parameters

$value

string

$repopulate

bool

Returns

\Fuel\Core\Fieldset_Fieldthis, to allow chaining

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

validated() : mixed

Returns

mixed

template()

template($build_field) 

Parameters

$build_field

 Properties

 

<p>Attributes for form generation</p>

$attributes : array

 

<p>Base name of this field</p>

$basename : string

 

<p>Description text to show with the field</p>

$description : string

 

<p>overwrites for default error messages</p>

$error_messages : array

 

<p>Fieldset this field belongs to</p>

$fieldset : \Fuel\Core\Fieldset

 

<p>Field label for validation errors and form label generation</p>

$label : string

 

<p>Name of this field</p>

$name : string

 

<p>Options, only available for select, radio /p>

$options : array

 

<p>Rules for validation</p>

$rules : array

 

<p>Template for form building</p>

$template : string

 

<p>Field type for form generation, false to prevent it showing</p>

$type : string

 

<p>(Default) value of this field</p>

$value : mixed