I am using a login form on Symfony2 with the following controller code
public function loginAction(Request $request)
{
$user = new SiteUser();
$form
Simply :
$data = $form->getData();
To get the data of a specific field,
$form->get('fieldName')->getData();
Or for all the form data
$form->getData();
Link to docs: https://symfony.com/doc/2.7/forms.html
If you're using Symfony 2 security management, you don't need to get posted values, you only need to manage form template (see documentation).
If you aren't using Symfony 2 security management, I advise you strongly to use it. If you don't want to or if you can't, can you give us the LoginType
's sources ?
If you have extra fields in the form that not defined in Entity , $form->getData()
doesn't work , one way could be this :
$request->get("form")["foo"]
Or :
$form->get('foo')->getData();
For not mapped form fields I use $form->get('inputName')->getViewData();
None of the above worked for me. This works for me:
$username = $form["username"]->getData();
$password = $form["password"]->getData();
I hope it helps.