i have a problem with my Form in symfony.
first the code:
$test = array();
foreach($docGrp as $dc){
$test[] = $dc->getGruppenName();
}
$form = $this->createFormbuilder($document)
->add('gruppe', 'choice', array(
'choices' =>array(
'Gruppen' => $test,
),
'multiple' => true,
'expanded' => true,
))
->getForm();
I want that the array is displayed as checkboxes and the values of it should be the values in the array. However, i get an Exception which says
“An exception has been thrown during the rendering of a template (“Warning: strtr() expects parameter 1 to be string, array given”
So if i change the choices to “Gruppen => “test” it works. But it defeats the purpose, i need to get those values out of the array.
If someone knows what i mean, help would be cool 🙂
so far
Adi
The problem is the way you’re passing the choices through in the form. Because $test is an array you’re actually passing a 2d array through as the choices option, e.g. array(‘Gruppen’ => array(….)), which is not allowed.
I’ve seen 2d arrays work when using a multiple select widget in Symfony. Where the widget indents the choices as the dimensions grow. But it doesn’t work with checkboxes.
What you want to do is pass an array like:
Where the array keys are the values.