Form_Model Class Reference

Model a form, which can be rendered. More...

Public Member Functions

 __construct ($action, $method, array $renderable_children=array())
 Create a form with a given set of fields.
 needs_csrf ()
 Returns whether this form's submission requires a CSRF token.
 get_method ()
 Gets the method of the form.
 add_field (Form_Field_Model $field)
 Add a new field to the end of the form.
 get_field_view (Form_Field_Model $field)
 Get a view representing a given field in the form.
 get_fields ()
 Get the list of fields in the form.
 get_id ()
 get the id of this form
 add_button (Form_Button_Model $button)
 Add a new button to the end of the form.
 get_button_view (Form_Button_Model $button)
 Get a view representing a given button in the form.
 get_buttons ()
 Get the list of buttons in the form.
 get_view ()
 Get a view representing a given field in the form.
 process_data (array $raw_data)
 Process and validate raw input data to the form.
 get_value ($fieldname, $default=null)
 Get the value of a field, formatted as result of process_data().
 set_values (array $values)
 Set the default values for the form.
 set_optional (array $fieldnames)
 Set which fields are optional.
 get_optional ()
 Returns an array of the fields that are optional.
 is_field_required (Form_Field_Model $field)
 Returns whether a Form_Field_Model is required within this form.

Detailed Description

Model a form, which can be rendered.


Constructor & Destructor Documentation

Form_Model::__construct ( action,
method,
array $  renderable_children = array() 
)

Create a form with a given set of fields.

Parameters:
$action string
$method string POST, PUT, PATCH, GET The HTTP method to use when submitting the form
$renderable_children array of From_Field_Model|Form_Button_Model

Member Function Documentation

Form_Model::add_button ( Form_Button_Model button  ) 

Add a new button to the end of the form.

Parameters:
$button Form_Button_Model
Form_Model::add_field ( Form_Field_Model field  ) 

Add a new field to the end of the form.

Parameters:
$field Form_Field_Model
Form_Model::get_button_view ( Form_Button_Model button  ) 

Get a view representing a given button in the form.

If no button is specified, a view for the entire form is returned

Parameters:
$button Form_Button_Model
Returns:
View
Form_Model::get_buttons (  ) 

Get the list of buttons in the form.

Returns:
array of Form_Button_Model
Form_Model::get_field_view ( Form_Field_Model field  ) 

Get a view representing a given field in the form.

If no field is specified, a view for the entire form is returned

Parameters:
$field Form_Field_Model
Returns:
View
Form_Model::get_fields (  ) 

Get the list of fields in the form.

Returns:
array of Form_Field_Model
Form_Model::get_id (  ) 

get the id of this form

Returns:
string id of this Form_Model
Form_Model::get_method (  ) 

Gets the method of the form.

Returns:
string
Form_Model::get_optional (  ) 

Returns an array of the fields that are optional.

Returns:
array
Form_Model::get_value ( fieldname,
default = null 
)

Get the value of a field, formatted as result of process_data().

It should be possible to recreate a form state as:

$form_b->set_values( $form_a->process_data($rawdata) );

Parameters:
$fieldname string
$default mixed = null
Returns:
mixed
Form_Model::get_view (  ) 

Get a view representing a given field in the form.

If no field is specified, a view for the entire form is returned

Returns:
View
Form_Model::is_field_required ( Form_Field_Model field  ) 

Returns whether a Form_Field_Model is required within this form.

Parameters:
$field Form_Field_Model
Returns:
bool
Form_Model::needs_csrf (  ) 

Returns whether this form's submission requires a CSRF token.

Returns:
bool
Form_Model::process_data ( array $  raw_data  ) 

Process and validate raw input data to the form.

Map the raw data from for example $_POST (as input prameter) to a validated and processed set of elements.

Elements not related to the form are not returned (might also be fields depending on other fields that are hidden)

The result might also be processed to match a given format. For example, an object selector which takes a unique key string as raw argument can return an actual object instance.

Parameters:
$raw_data array of parameters fetched as $_POST
Returns:
array
Form_Model::set_optional ( array $  fieldnames  ) 

Set which fields are optional.

Optional fields are handle in such a way that if the process_data function of that field throws a MissingValueException, that exception is ignored.

Optional fields that throw MissingValueException are NOT part of the array result of the form->process_data call.

Parameters:
$fieldnames array
Form_Model::set_values ( array $  values  ) 

Set the default values for the form.

Parameters:
$values array

The documentation for this class was generated from the following file:
 All Data Structures Functions Variables

Generated on 19 Dec 2018 for ninja by  doxygen 1.6.1