Symfony2 : How to get form validation errors after binding the request to the form

symfony

Solution

You have two possible ways of doing it:

- do not redirect user upon error and display `{{ form_errors(form) }}` within template file

- access error array as `$form->getErrors()`

Problem

Here's my `saveAction` code (where the form passes the data to) ``` public function saveAction() { $user = OBUser(); $form = $this->createForm(new OBUserType(), $user); if ($this->request->getMethod() == 'POST') { $form->bindRequest($this->request); if ($form->isValid()) return $this->redirect($this->generateUrl('success_page')); else return $this->redirect($this->generateUrl('registration_form')); } else return new Response(); } ``` My question is: how do I get the errors if `$form->isValid()` returns `false`?

Original source