Setting default selected option for Zend_Form_Element_Select [duplicate]
Possible Duplicate:
Zend Framework - Set 'selected' value in select box dropdown list
I have a Zend_Form with Zend_Form开发者_如何转开发_Select element. I populate it from array (code inside the Application_Form_MyForm extends Zend_Form class):
$options = array('first option', 'second option', 'third option');
$this->getElement('mySelect')->addMultiOptions($options);
How can I choose which value is gonna be selected automatically, as in "<option value="second option" selected="selected">second option</option>" ?
Thanks!
To populate all form values, you can call $form->populate($dataAsArray);
If you want to set a default value, you can call $select->setValue('valueHere'); If it were a checkbox, instead of pass one sigle value you would pass an array of selected indexes.
See this question: Zend_Form_Element_MultiSelect element definition
Nevermind... populating values of whole form from array ($form->populate) did the trick. I didn't see it working before I dont know why, maybe some bug or the browser aggressively caching.
精彩评论