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

前端 未结 6 995
天命终不由人
天命终不由人 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 could try to use the dump function when the form is submited and not valid. I use it like this

    if($form->isSubmited() && $form->isValid()){
       //SAVE TO DATABASE AND DO YOUR STUFF
    }else if($form->isSubmited()){
      //SUBMITED BUT WITH ERRORS
       dump($form->getErrors(true));
       die();
    
    }
    

    Note this is for debugging purposes only, It will show you your form, the data in it and all the errors any field could have. In production mode you should return the error to the view and show them to the user.

提交回复
热议问题