Symfony2: my form returns false from isValid() but empty array for getErrors() from unique constraint condition

前端 未结 6 852
天命终不由人
天命终不由人 2021-02-13 04:02

I have a Customer entity that only has a unique Email field to it. I am trying to edit a customer\'s email and the validation works fine. However I have this in my controller:

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-13 04:47

    In Symfony 2.3, you can use this one :

    if ($form->isValid()){
        # Code...
    } else {
        foreach ($form->getIterator() as $key => $child) {
            if ($child instanceof Form) {
                foreach ($child->getErrors() as $error) {
                    $errors[$key] = $error->getMessage();
                }
            }
        }
    }
    

    This will get you an array ($errors) with the errors from the children.

提交回复
热议问题