you would just do this

try this first:

$data = array(
    'location' => 'location1'
);
$form->populate($data); 


when the form is displayed it should show a select list of location options
with location1 selected.


now try



$data = array(
    'location' => 'location2'
);
$form->populate($data);

now location12 should be selected when the form is displayed.


does that help? 




Deepak Shrestha wrote:
> 
>> 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.
>>
>>
> 
> Ok, just help me in this part
> 
> As I mention i my first post, I have table called location with field
> "locname" as only field and also the primary key for that table (there
> is no locationid, locname).
> 
> so If I retrieve data from that table (to array) I will have array of
> locations.
> e.g. $data = array('location1', 'location2', ... and so on);
> 
> in my form, if I have to hand code to fill the select, I will be doing
> something like this:
> 
>        $location= New Zend_Form_Element_Select('location');
>        $location->setLabel('*Location:');
>        $location->setMultiOptions(array('location1' => 'location1',
> 'location2' => 'location2' .... and so on));
> 
> My question is how do I do the same thing with the previous method (
> controller passes the retrieved data to form and form will iterate to
> populate data in select element).
> 
> I guess it is clear now.
> - Hide quoted text -
> 
> Thanks
> 
> --
> =======================
> Registered Linux User #460714
> Currently Using Fedora 8, 10
> =======================
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Populating-Zend_Form_Element_Select-from-database-example-tp21761696p21764210.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to