Radio button, checkbox, dropdown
Add Field
// Radio button example
$form->addField('Gender', 'radio', array('options' => ['male', 'female', 'other'],
'required' => false
));
// checkbox example
$form->addField('News', 'checkbox', array('label' => 'How often shall we send you news?',
'options' => ['Weekly', 'Fortnightly', 'Monthly']
));
// dropdown example
$form->addField('Language', 'dropdown', array('first' => 'Please select your language',
'options' => ['English', 'German', 'Turkish']
));
You can use key / value pairs within the options too if you need a specific return value:
// Option field with custom keys
$form->addField('Color', 'radio', [
'options' => [
'ff0000' => 'Red',
'00ff00' => 'Green',
'0000ff' => 'Blue'
/*
* NOTE: key must be a string.
* If you want to use a numeric key, you have to append some letters, e.g. id__1
*/
]
]);
Attributes
You can customize the field with one of these optional parameters:
Parameter | Type | Default | Info |
---|---|---|---|
required | boolean | true | Validation will return false when the field is left empty |
classlist | string | has-error will be added to classes if validation returns false.is-valid will be added if the validation was successful.
|
Add classes to input field and its field wrap e.g. column-with classes of a grid system. |
options | array | Selection options as array (required) | |
label | string | Label for input field | |
default | string | Pre selected option. Use the array key here if you provide the options as an associative array (key / value pairs). | |
first | string | For dropdowns only! This is the first option that cann't be selected, e.g: Please choose an option: |
|
disabled | string | false | Disable field if it only is available under specific circumstances. |