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

前端 未结 6 855
天命终不由人
天命终不由人 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:51

    You can use error_bubbling on each field to bubble the error up to your $form.

    If not, you can also foreach through the errors

    foreach ($children as $child) {
                if ($child->hasErrors()) {
                    $vars = $child->createView()->getVars();
                    $errors = $child->getErrors();
                    foreach ($errors as $error) {
                        $this->allErrors[$vars["name"]][] = $this->convertFormErrorObjToString($error);
                    }
                }
    }
    

提交回复
热议问题