Symfony2 invalid form without errors

The first thing to understand is validation is done on the model, not the form. The form can contain errors, but only if it has a field mapped to the property that doesn’t validate. So if your form does not contain the invalid field (maybe a NotNull assertion on a property that is not in the form), it will not show the error.

The second thing is that $form->getErrors() will only show errors for that level, each form child can contain its own errors. So if you want to check the errors, you should loop through the fields and call getErrors on each field. The getErrors method on the Form class can be deceiving that way.

Leave a Comment