I'm new to Symfony2 (version 2.7) and I'm trying to get the value from a submitted form. Using $form->getData(), I get the index corresponding to the selected value in the list.
For example, assuming $test is an array:
$form = $this->createFormBuilder($test)
->add('abc', 'choice',
array('choices' => array(
'0' => 'option1',
'1' => 'option2',
'2' => 'option3'
)))
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$data = ($form->getData());
}
Then, $data will be 1 if I select option2.
I've also tried to set choices_as_values to true, but then I got the array indexes in the drop-down list.
What can I do to get $data equal to option2 ?