Setting "selected" option in Zend_Form_Element_Select
I'm new to ZF, PHP and web-programming in general, and I'm having problems with the Zend_Form_Element_Select component. I'm using a Zend_Form to display some data from a database so the user can edit it. One of the fields is displayed using a Select (dropdown) box which is pre-populated with valid values from a DB reference table when the form is first instantiated.
When I populate the form with the data for the record I want to edit, all the form fields seem to be set correctly internally, and if I do a getValue() on my dropdown element, it returns the correct value i.e. the value from my record.
But when the form is displayed, it does not set the "selected" option on the dropdown to the current value of the corresponding DB field.
Right now the form is producing the equivalent of
<option value="fiat">Fiat</option>
as the HTML for the selected option, but it should produce something like:
<option value="fiat" selected="selected">Fiat</option>
How do I tell the select element which of its options is "selected", so that it will display with the correct value pre-selected?
I can't find any methods in the relevant classes to do this, so any help will be greatly appreciated!
Thanks,
Chris
|