PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Henrik Bjørnskov's Blog: Symfony2: Using the validator symfony1 style

Note: This article was originally published at PHPDeveloper on 4 February 2012.
PHPDeveloper

In this quick new post to his blog Henrik Bjørnskov shows how to use the validators in Symfony2 in a more traditional Symfony 1 style for a form.

Two of the more complicated components in Symfony2 is the Form and Validator component. The Validator is created in such a way it "always" need an Domain Object with Constraints associated through metadata. This is explained in detail here. But there is another way. A way that resemble's the symfony1 forms. Where you could specify the validations directly in your form class.

Code is included in the post to show how to load in a few of the validators (like NotBlank, Email and Choice) and how to use them in the settings defined in the "getDefaultOptions" method.