Fieldset Class
The Fieldset class is used to create a form and handle its' validation in an object oriented way. It uses the Form
and Validation classes. This class itself is only meant to model the fieldset and its fields while the other
two classes do the real work.
The resulting form markup is generated when passing the Fieldset instance to a View or by calling build().
factory($name = 'default', $config = array())
The factory method returns a new Fieldset instance. Note: there can only be one instance per $name.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$name |
'default' |
Identifier for this fieldset |
$config |
array() |
Configuration array |
|
Returns |
Fuel\Core\Fieldset Object |
Example |
$article_form = Fieldset::factory('article');
|
instance($instance = null)
Returns a specific instance, or the default instance (is created if necessary).
Static |
Yes |
Parameters |
Param |
Default |
Description |
$instance |
null |
Identifier of the fieldset instance you want to retrieve |
|
Returns |
Fuel\Core\Fieldset Object
or false if the specified instance doesn't exist. |
Example |
$article_form = Fieldset::instance('article');
|
validation()
Gets the Validation instance for the current Fieldset. Creates the Validation instance if it doesn't already exist.
Static |
No |
Returns |
Fuel\Core\Validation Object |
Example |
$validation = $article_form->validation();
|
form()
Gets the Form instance for the current Fieldset. Creates the Form instance if it doesn't already exist.
Static |
No |
Returns |
Fuel\Core\Form Object |
Example |
$form = $article_form->form();
|
instance($instance = null)
Returns a specific instance, or the default instance (is created if necessary).
Static |
Yes |
Parameters |
Param |
Default |
Description |
$instance |
null |
Identifier of the fieldset instance you want to retrieve |
|
Returns |
Fuel\Core\Fieldset Object
or false if the specified instance doesn't exist. |
Example |
$article_form = Fieldset::instance('article');
|
add($name, $label = '', array $attributes = array(), array $rules = array())
Creates a Fieldset_Field instance and adds it to the current Fieldset.
Static |
No |
Parameters |
Param |
Default |
Description |
$name |
required |
HTML name attribute, also used for referencing the field within the Fieldset |
$label |
'' |
Field label |
$attributes |
array() |
HTML attributes as an associative array |
$rules |
array() |
Validation rules to be applied to this Field |
|
Returns |
Fuel\Core\Fieldset_Field Object |
Example |
$title_field = $article_form->add('article_title', 'Title', array('class' => 'pretty_input'));
|
field($name = null)
Gets one or all Fieldset_Field instances for the current Fieldset.
Static |
No |
Parameters |
Param |
Default |
Description |
$name |
null |
The name of an existing field in this Fieldset or null to get all fields. |
|
Returns |
Fuel\Core\Fieldset_Field Object
or array() of Fieldset_Fields |
Example |
$fields = $article_form->field();
$title_field = $article_form->field('article_title');
|
add_model($class, $instance = null, $method = 'set_form_fields')
Add a model's fields. The model must have a method set_form_fields() that takes this Fieldset instance and adds fields to it.
Static |
No |
Parameters |
Param |
Default |
Description |
$class |
required |
Either a full classname (including full namespace) or object instance of the model to get fields from. |
$instance |
null |
Array or object that has the exactly same named properties to populate the fields. (Takes the field names from the model and fetches the remaining parameters from this array/object. |
$method |
'set_form_fields' |
The name of the method name to call on the model for field fetching. |
|
Returns |
Fuel\Core\Fieldset Object |
Example |
$article_form = Fieldset::factory('article');
$article_form->add_model('Model_Article');
|
set_config($config, $value = null)
Sets a config value on the fieldset.
Static |
No |
Parameters |
Param |
Default |
Description |
$config |
required |
Configuration array. |
$value |
null |
If specified, sets the item to set from the passed Configuration array. |
|
Returns |
Fuel\Core\Fieldset Object |
Example |
$article_form->set_config($config);
|
get_config($key = null, $default = null)
Get the configuration array or one or more config values by key.
Static |
No |
Parameters |
Param |
Default |
Description |
$key |
null |
A single key or multiple in an array, empty to fetch all. |
$default |
null |
A single config value or multiple in an array if $key input is an array to be returned if the items aren't found. |
|
Returns |
array() or mixed |
Example |
$config = $article_form->get_config();
|
repopulate($input = null)
Set all field values to the given and/or posted input.
Static |
No |
Parameters |
Param |
Default |
Description |
$input |
null |
An associative array of values to assign to their respective Fields, or a Model instance to take the values from. If null, tries to fetch values from POST data. |
|
Returns |
Fuel\Core\Fieldset Object |
Example |
$article_form->repopulate();
|
build($action = null)
Alias for $this->form()->build() for this fieldset. Generates the HTML form markup. See Form.
Static |
No |
Parameters |
Param |
Default |
Description |
$action |
null |
A URL for the action attribute of the form. |
|
Returns |
string HTML markup |
Example |
$this->template->form = $article_form->build(Uri::create('article/submit'));
|
input($field = null)
Alias for $this->validation()->input(). Gets an array of validated input value(s) from either POST data or given input. See Validation.
Static |
No |
Parameters |
Param |
Default |
Description |
$field |
null |
A specific field for which to get the input. |
|
Returns |
Array of input or string value of specified field |
Example |
$input_values = $article_form->input();
|
validated($field = null)
Alias for $this->validation()->validated(). Gets an array of input value(s) that passed validation. See Validation.
Static |
No |
Parameters |
Param |
Default |
Description |
$field |
null |
A specific field for which to get the input. |
|
Returns |
Array of input or string value of specified field, or false if the field isn't found |
Example |
$validated_values = $article_form->validated();
|
errors($field = null)
Alias for $this->validation()->errors(). Gets an array of input value(s) that did not pass validation. See Validation.
Static |
No |
Parameters |
Param |
Default |
Description |
$field |
null |
A specific field for which to get the input. |
|
Returns |
Array of input or string value of specified field, or false if the field isn't found |
Example |
$validated_values = $article_form->validated();
|
show_errors(Array $config = array())
Alias for $this->validation()->show_errors(). Returns all errors in a list or with set markup from the $config parameter. See Validation.
Static |
No |
Parameters |
Param |
Default |
Description |
$config |
array() |
Uses keys open_list, close_list, open_error, close_error & no_errors. Overrides the values |
|
Returns |
Array of input or string value of specified field, or false if the field isn't found |
Example |
$validated_values = $article_form->validated();
|
More examples to be written.