Error Message
Errors can be automatically added to fields by adding a error attribute in the fields attribute array.
errors are used to pass further instructions to the user about a field element.
There are two ways of adding a error to your form object:
error (string message [, string for])
- message: a string defining the contents of the error message| required
- for: defines the errors related field. Will be used to create the errors class attribute | optional
Example:
$this->goodform->error('Username already taken, please choose another.', 'username');
Will produce the following HTML:
<p class="username-error error">Username already taken, please choose another.</p>
error (array attributes)
- attributes: an associative array specifying attributes of the element.
Example:
$attr = array(
'for' => 'username',
'value' => 'Username already taken, please choose another.',
'class' => 'my-error-class',
'title' => 'Please correct this error.'
);
$this->goodform->error($attr);
Will produce the following HTML:
<p class="my-error-class username-error error" title="Please correct this error." >Username already taken, please choose another.</p>