Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-17-2008, 11:42 AM
Junior Member
 
Join Date: Jun 2008
Location: Wales
Posts: 9
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-17-2008, 12:14 PM
Junior Member
 
Join Date: Jun 2008
Location: Wales
Posts: 9
Default

Found the problem:

The value in my database record had some trailing spaces, but the values in the dropdown options did not, so when the form was populated, the values did not match and the form could not set the dropdown value.

Removed trailing spaces from DB value and everything works fine.

Doh!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:18 PM.