Answer the question
In order to leave comments, you need to log in
Symfony2 forms How to call validator before transformer?
I have a field for entering a date (widget text) on the form.
I need to check it with a regular expression, then convert it to Datetime.
To check, I add a constraint of the Regex type in the form class, to convert - addModelTransformer or addViewTransformer. Well, Regex throws an error, since DateTime is passed to it instead of a string. I would not like to take out the transformation in the controller.
Answer the question
In order to leave comments, you need to log in
The fact is that validation is checked during the reverse transformation, therefore, transformation always takes place first, and only then - validation.
You must do validation not through the standard Constraints, write your own validation, and run it through an event using FormEvents::PRE_SUBMIT
.
This answer has a little more information about it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question