How to get form values in Symfony2 controller How to get form values in Symfony2 controller symfony symfony

How to get form values in Symfony2 controller


Simply :

$data = $form->getData();


None of the above worked for me. This works for me:

$username = $form["username"]->getData();$password = $form["password"]->getData();

I hope it helps.


In Symfony 2 ( to be more specific, the 2.3 version ) you can get a data of an field by

$var = $form->get('yourformfieldname')->getData();

or you can get all data sent

$data = $form->getData();

where '$data' is an array containing your form fields' values.