User Created Image
User Created Image

Reputation: 1182

Dynamic form validation in symfony2

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?

Upvotes: 1

Views: 9603

Answers (2)

User Created Image
User Created Image

Reputation: 1182

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)

Upvotes: 3

Bernhard Schussek
Bernhard Schussek

Reputation: 4841

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.

Upvotes: 2

Related Questions