How to Define the Validation Groups to Use

Version: 3.2
Edit this page

Warning: You are browsing the documentation for version 3.2 which is not maintained anymore.

If some of your projects are still using this version, consider upgrading.

How to Define the Validation Groups to Use

Validation Groups

If your object takes advantage of validation groups, you'll need to specify which validation group(s) your form should use:

1
2
3
$form = $this->createFormBuilder($users, array(
    'validation_groups' => array('registration'),
))->add(...);

If you're creating form classes (a good practice), then you'll need to add the following to the configureOptions() method:

1
2
3
4
5
6
7
8
use Symfony\Component\OptionsResolver\OptionsResolver;

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'validation_groups' => array('registration'),
    ));
}

In both of these cases, only the registration validation group will be used to validate the underlying object.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.