Setting default selected option for Zend_Form_Element_Select

12,526

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

Share:
12,526
Sejanus
Author by

Sejanus

Updated on June 05, 2022

Comments

  • Sejanus
    Sejanus almost 2 years

    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!