Before receiving $_POST
information from form submission, I didn't know anything about the number of fields, types or validation rules (whether the field is required, whether 开发者_运维知识库it should be a valid email, etc.)
In ohter words, the validation rules and fields depend on what i receive in $_POST
:
user creates form fields and defines validation rules by himself.
So I need to set validation rules after I'll receive $_POST
What will be most right method to do this in symfony2?
The solution was simple: http://symfony.com/doc/current/book/forms.html#adding-validation
(It seems this paragraph was added not long time ago, or i don't know)
This is exactly the same thing that happens in CollectionType. There the ResizeFormListener instance listens to the preBind
event to dynamically add or remove fields. You should do the same.
精彩评论