Symfony forms question (restoring selected value of a dynamically populated sfWidgetFormSelect widge

Posted by Stick it to THE MAN on Stack Overflow See other posts from Stack Overflow or by Stick it to THE MAN
Published on 2010-03-09T09:45:55Z Indexed on 2010/03/09 10:51 UTC
Read the original article Hit count: 616

Filed under:
|
|
|

I am using Symfony 1.3.2 with Propel ORM on Ubuntu 9.10.

I have developed a form that dynamically populates a select widget with cities in a selected country, using AJAX.

Before the data entered on the form is saved, I validate the form. If validation fails, the form is presented back to the user for correction. However, because the country list is dynamically generated, the form that is presented for correction does not have a valid city selected (it is empty, since the country widget has not changed yet).

This is inconvenient for the user, because it means they have to select ANOTHER country (so the change event is fired), and then change back to the original country they selected, then FINALLY select the city which they had last selected.

All of this is forced on the user because another (possibly unrelated) field did not vaildate.

I tried $form->getValue('widget_name'), called immediately after $form->bind(), but it seems (infact, IIRC, if form fails to validate, all the values are reset to null) - so that does not work.

I am currently trying a nasty hack which involves the use of directly accesing the input (i.e. tainted) data via $_POST, and setting them into a flash variable - but I feel its a very nasty hack)

What I'm trying to do is a common use case scenario - is there a better way to do this, than hacking around with $_POST etc?

© Stack Overflow or respective owner

Related posts about symfony

Related posts about php