Symfony – Don’t have form_error when removing required attr from source code

I just noticed in my symfony project that if I have an entity that has a non-nullable field, and that in the formType I make sure that the field is required.

So in the rendering of the page, if I do “inspect the element” and I manually remove the “required” attribute from the field, well I can validate, and in this case I will have a doctrinal error instead of staying on the form page with a simple validation error

SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ ‘titre’
ne peut ĂȘtre vide (null)

However, I use {{form_row(form.field)}} in my Twig file, so I should have the form_error too.

Does this mean that for all my entities, I have to add @AssertNotNull each time to avoid this problem? It seems far-fetched even if it is not managed automatically

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *