Special attributes
When adding a form element to your form you can include a number of special attributes to the attributes array that will trigger special features
| Attribute | Description |
|---|---|
| label | Adds a label element to the form before the field. label = the labels string name = the labels for attribute. If the label string is blank goodform will not add the element |
| description | Adds a tooltip element to the form after the field. description = the tooltip string name = will be prefixed to -tooltip to form a unique class for the tooltip. If the description string is blank goodform will not add the element |
| error | Adds an error message element to the form after the field. error = the fields error message string name = will be prefixed to -error to form a unique class for the error message. If the error string is blank goodform will not add the element |
| validation | Set the form elements validation rules. Separate multiple rules with a pipe e.g. required|valid_email If a field fails validation, the error message will be automatically added when run() is called. |
Examples of use
Adding a label to a form field.
$attr = array(
'name' => 'email',
'value' => 'me@example.com',
'label' => 'Email'
);
$this->goodform->text($attr);
Will produce the following HTML:
<label for="email">Email</label>
<input name="email" value="me@example.com" type="text"/>
Adding a description tooltip to a form field.
$attr = array(
'name' => 'about',
'cols' => 30,
'rows' => 10,
'description' => 'Keep it to 256 characters or less please!'
);
$this->goodform->textarea($attr)
Will produce the following HTML:
<textarea name="about" cols="30" rows="10"></textarea>
<p class="about-tooltip tooltip">Keep it to 256 characters or less please!</p>
Adding an error message to a form field.
$attr = array(
'name' => 'email',
'value' => 'me@example.com',
'error' => 'The password field is required'
);
$this->goodform->text($attr);
Will produce the following HTML:
<input name="password" type="password"/>
<p class="password-error error">The password field is required</p>
Adding an validation rules to a form field.
$attr = array(
'name' => 'email',
'value' => 'me@example.com',
'validation' => 'required|valid_email'
);
$this->goodform->text($attr);
Doin' all four!
$attr = array(
'name' => 'username',
'label' => 'Your Username',
'error' => 'This username has already been taken, please choose another.',
'description' => 'Usernames must contain alpha-numeric characters and be less than 32 characters.',
'validation' => 'required|alpha_numeric'
);
$this->goodform->text($attr);
Will produce the following HTML:
<label for="username">Your Username</label>
<input name="username" type="text"/>
<p class="username-tooltip tooltip">Usernames must contain alpha-numeric characters and be less than 32 characters.</p>
<p class="username-error error">This username has already been taken, please choose another.</p>