1

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?

4
  • Do you mean the validation rules and fields depend on what you receive in $_POST? If yes you should probably clarify this in your question. Commented Oct 2, 2011 at 12:45
  • Yes, thanks, i mean that. Question edited. Commented Oct 2, 2011 at 13:00
  • You didn't draw the problem with too many details. It might be that validation groups would solve it. With more complex rules you might implement your validation rules in custom validators. That depends on what you really want to solve. Commented Oct 2, 2011 at 13:52
  • I edited question and added more details to explain what i want. User creates form fields and defines validation rules by himself, then submit it. Commented Oct 2, 2011 at 14:06

2 Answers 2

3

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)

Sign up to request clarification or add additional context in comments.

Comments

2

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.

1 Comment

Sorry, but i don't understand how it can help validate $_POST array dynamically? (without predefined model). There is no problem creating form dynamically. Can you please explain your answer with more details?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.