I’m doing a filter form in symfony2
and I try to preselect some filds.
I got two choices:
$formBuilder->add('first', 'choice',
array('choices' => $choiceFirst,
'expanded' => false,
'multiple' => true,
'data' => explode(' ', $this->getRequest()->get('first'))
));
$formBuilder->add('second', 'choice',
array('choices' => $choiceSecond,
'expanded' => true,
'multiple' => true,
'data' => explode(' ', $this->getRequest()->get('second'))));
For the first choice which is not expanded the datas pass by url are preselect.
But not for the second which is expanded.
There is any ways to preselect checkboxs from a field choice?
You must provide an array of selected values as data for a multiple choice field.edit: irrelevant answer, my mistake
Try to provide a key => boolean array as the checked state depends on a boolean value.
I think you only have to put checked value in your array, so those one that are true 😉