I recently found a strange issue when coding a form using ZF1’s Zend_Form
in combination with checked
checkboxes.
The code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$options = array(1=>'banana',2=>'apple',3=>'car',); $checked = array(1,2); $form =new \Zend_Form; $form->addElement('multiCheckbox','test1', array('value'=> $checked,'multiOptions'=> $options,)); $form->addElement('multiCheckbox','flags', array('value'=> $checked,'multiOptions'=> $options,)); echo $form; |
The issue:
The first 3 checkboxes are getting displayed normally, with banana and apple pre-checked. The second multiCheckbox
renders, but does not have any checkboxes checked.
Why:
In my case I got it working when I renamed 'multiCheckbox', 'flags', array(
to for example 'multiCheckbox', 'matchingFlags', array(
.
Conclusion: flags
in Zend_Form
is a reserved word causing issues.