-
Notifications
You must be signed in to change notification settings - Fork 5
forms customization
Harmen Janssen edited this page Aug 22, 2016
·
4 revisions
Most attributes can be included in $options
:
$form->addElement('text', 'something', array(
'autocomplete' => 'off'
));
Sometimes an option-name is reserved by Zend for another feature however, so just remember that you can always add attributes like this:
$myField = $form->createElement('text', 'something');
$myField->setAttrib('autocomplete', 'off');
$form->addElement($myField);
This is especially valuable when rendering checkboxes:
$checkbox = $form->createElement('checkbox', 'legal', array(
'label' => 'I\'ve read the terms and conditions'
));
$checkbox->getDecorator('Label')->setOption('placement', 'append');
$form->addElement($checkbox);
For instance: I agree to the terms and conditions. Simply add 'escape' as an option:
$form->addElement('checkbox', 'terms', array(
'label' => 'I agree to the <a href="#">terms and conditions</a>',
'escape' => false
));
$form->addElement('file', 'avatar', array(
'label' => 'Upload your avatar',
'description' => 'max 20MB, allowed extentions: JPG, GIF, PNG'
));
$form->addElement('html', 'h2', array(
'value' => 'feedback & suggestions',
'class' => 'foobar'
));
// Renders: <h2 class="foobar">feedback & suggestions</h2>
class App_Form_EducationBooking extends Garp_Form {
protected $_defaultRequiredLabelSuffix = '⭐️';
public function init() {
parent::init();
// ...
}
}