Tag: forms
Why Doesn’t My Form Default Work?
by scott on Feb.21, 2009, under symfony
Here’s a little tip for symfony forms. It’s a bug really. Cost me around three hours.
Forms are closely tied to the database model (like it or not). Their default values are bound to the Doctrine model class specified in the getModelName() call. For example, if you specify a default value for STATUS in your schema and then have a form element called STATUS, the form processor will bind the default value from your schema to your form element and IGNORE the default that you set in the form element itself.
For example, if you have the following widget specified in your form
’status’ => new sfWidgetFormSelectRadio(array(’choices’ => self::$choices, ‘default’ => self::DEFAULT_CHOICE))
you’ll might be surprised to find that the default you picked for the radio group is not lit up as it should be. If that’s the case, its probably because your database schema specified a default for STATUS. Using the default from the model is a good thing, but a programmatically specified default should have precedence. It’s a bug, in my opinion.
The solution is to set the default values in your schema to null (or none) which causes symfony to properly use the programmatically set default.