I have a form with a dropdown (select) and I would like to choose the option selected by default:
This is the code that generates the select:
$builder->add('language', 'choice', array(
'label' => 'pages.age.gateway.language.label',
'choices' => array(1 => 'first option', 2 => 'second option'),
));
I've tried the following (suggested here, Symfony2 Setting a default choice field selection):
$builder->add('language', 'choice', array(
'label' => 'pages.age.gateway.language.label',
'choices' => array(1 => 'first option', 2 => 'second option'),
'data' => '2'
));
this didn't work with my code (my understanding of symfony2, I might not be in the right direction).
Another alternative would be using 'preferred_choices' but I'd like to avoid this, as I wouldn't like to modify the order in which the options are displayed.