It looks like your doing it correct except for the array of data that you're
using to populate the form. You're not actually populating the select
element with options, you only want the current Or selected option to be
selected in the select list on display.
So in your case it's probably a location id,
$data = array(
'location_id' => 2
);
$form->populate($data);
Change location_id to whatever the id of the select element is.
Deepak Shrestha wrote:
>
> sorry! Reply in gmail sent the private message instead of mailing
> list. so I am posting again to the list
>
> ---------------------------------------
>> This might help,
>> http://peacocksuit.com/blog/2008/08/30/populate-a-zend_form-select-with-mysql-returned-data/
>>
>
> I had a look at it but still confused.
>
> 1. Isn't that form should not manipulate data directly from table?
> 2. Besides that I want to know how $form->populate($data) works in
> zend framework's ideal condition.
>
> ===================
>
> OK to the point.
>
> in my controller, I have
> ==================
> $data = array('rat', 'cat');
> $form = $this->_getTestForm();
> $form->populate($data);
> ...
> ....
> ==================
>
> in my form, I have
> ===========================================
> $location = New Zend_Form_Element_Select('adlocation');
> $location->setLabel('*Location:');
> foreach($this->data as $loc) <<<<<< is $data passed from controller
> directly accessed here?
> {
> $adlocation->addMultiOption($loc, $loc);
> }
> ...
> ...
> ===========================================
>
> Now when form renders, Select doesn't get populated.
>
> What is wrong with this code? plus how to make it work?
>
>
--
View this message in context:
http://www.nabble.com/Populating-Zend_Form_Element_Select-from-database-example-tp21761696p21763619.html
Sent from the Zend Framework mailing list archive at Nabble.com.