3

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!

Community
  • 1
  • 1
Sejanus
  • 3,253
  • 8
  • 39
  • 52

2 Answers2

3

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

Community
  • 1
  • 1
Keyne Viana
  • 6,194
  • 2
  • 24
  • 55
0

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
  • 3,253
  • 8
  • 39
  • 52