views:

59

answers:

2

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!

A: 

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.

Sejanus
A: 

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: http://stackoverflow.com/questions/3488057/zend-form-element-multiselect-element-definition/3488129#3488129

Keyne