Take the 2-minute tour ×

I have the following Symfony2 form:

public function buildForm(FormBuilder $builder, array $options)
        ->add('submitter_is_home', 'choice', array(
            'expanded' => true,
            'choices' => array('1' => 'Home', '' => 'Away'),
            'data' => '1',

(I omitted my other fields for clarity.)

When I visit this form in the browser, the "Home" option is not selected. I checked the source, too, and it doesn't look like the proper attribute is set there, either.

Does the default value work differently for radio buttons than for other types of choice fields? What could be going on here?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

If you want an option to be selected the empty_value will not work.

The simply solution is to set a value to your object before adding the form (like $myentity->setRadiobutton(1)). Symfony will understand and add it as a selected value (works with choice type so might be the same with radio!)

share|improve this answer
You're correct: that worked for my radio button. Thanks! –  Jason Swett Mar 29 '12 at 16:04
It won't help with a form element set as 'property_path' => false. –  marden Jan 17 '13 at 11:48
and when you have form without entity ? –  altore Nov 26 '13 at 16:37
give an array to the form type instead of an object with as key the key in your form type and as value 1 or true (probably, didn't test it). Should do the trick –  Coussinsky Nov 27 '13 at 11:10
In my case, i used a 'choise' type field called 'type', without entity. Solution: $form->get('type')->setData('default_val'); –  ZeeCoder Aug 15 at 9:12

Your Answer


