i have a multiselect box (of interests) in my zend form, and i am selecting multiple options from it while i am adding a user.
Now when i am editing this user, i need to set some options selected by default, (which i selected while adding the user).
How can i achieve this? I used populate(Array) in my controller's update action, but that does not work.
This is the code of multi select box in the user add/edit form:
$interests = new Zend_Form_Element_Multiselect('interest');
$days->setLabel('Interests')
->addMultiOptions($user_interests)
->setRequired(true)
->addValidator('NotEmpty');
And while adding the "interest" options in the form, $user_interests
array is:
array(1=>'Blogging', 2=>'Swimming', 3=>'Cricket', 4=>'Yoga')
I have selected the first 2 interests while adding the user.
Now while editing, i get the user data from a database query. This data array is used to populate the form, and this array structure is like this:
Array (
[username] => john
[user_dob] => 1981-03-12
[email] => [email protected]
[interest] => Array ( [0] => 1 [1] => 2 )
)
and as you can see, the interests "Blogging" and "Swimming" are supposed to be selected in my edit form. But i see that only the "Swimming" option is getting selected.
interest
key? – Vika