Symfony2 : How to get form validation errors after

2020-01-24 03:45发布

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?

标签: symfony
19条回答
Juvenile、少年°
2楼-- · 2020-01-24 04:15

For my flash messages I was happy with $form->getErrorsAsString()

Edit (from Benji_X80): For SF3 use $form->getErrors(true, false);

查看更多
登录 后发表回答