Form
From Utopia MVC
Represents a form to interact with user input, you can visit Form Boilerplates for structures you can copy-paste when creating forms.
Contents |
Properties
Inputs
- public array $inputs
A list of the input elements in the form. See Form::Inputs for more details.
Groups
- public array $groups
Used to created grouped sets of inputs, useful to handle complex forms, specially if they use fieldsets.
--Madness 17:34, 2 May 2011 (CEST) Documentation incomplete.
Options
- public array $options
General options pertaining to the whole form:
- $options['method']
- Can be 'post' or 'get', defaults to 'get' but is automatically set to 'post' if the form contains a password or an upload input.
- $options['target']
- Defines the target of the form action property, it defaults to $_SERVER['REQUEST_URI'].
- $options['enctype']
- Defines the encoding type of the form, can be 'multipart/form-data' or 'application/x-www-form-urlencoded', it defaults to 'multipart/form-data' but is automatically set to 'application/x-www-form-urlencoded' if the form contains an upload input.
Errors
- public array $errors
Usually empty, gets filled with an array of strings, each one of which is an error message.
TBD: errors specific to a form input should also be added to the input informations, so we can decide whether to put error reports grouped together or inline next to input elements.
Methods
__construct
- public __construct(string $ID)
Creates a form object with the passed id as token value.
populateInputs
- public populateInputs(array $inputs)
Merges the parameter array with the $inputs property
wasSubmitted
- public bool wasSubmitted(void)
Returns true if the form was submitted.
It achieves that by looking for the token input in the appropriate superglobal array ($_POST or $_GET).