MeuMySQL Blog is now at http://blog.mdnsolutions.com/.

Wednesday, August 29, 2012

[OFF-TOPIC][En] Zend_Form_Select with dynamic options


Hey Guys,

I'd like just to show off a really hand attribute to be used with select elements in Zend_Form.
It gives you the change of load options into your select fields without have that anoying message: "X  was not found in the haystack" (or in portuguese "X não faz parte dos valores esperados").

All you need to do is set the 'registerInArrayValidator' as false. Doing so Zend_Form is not validating the original set of values in your select element.



<?php
 ....
               $this->addElement('select', 'xptoId', array(
                    'label' => 'Xpto',
                    'multiOptions' => array(),
                    'registerInArrayValidator' => false,
                    'required' => true,
                ))

...
?>

Hope it is going to be hand for you mates!