开发者

Dynamic form validation in symfony2

开发者 https://www.devze.com 2023-04-09 18:41 出处:网络
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 shou

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消