You are browsing the documentation for Symfony 4.2 which is not maintained anymore.

Consider upgrading your projects to Symfony 5.3.

How to Define the Validation Groups to Use

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:

$form = $this->createFormBuilder($user, [
    'validation_groups' => ['registration'],

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

use Symfony\Component\OptionsResolver\OptionsResolver;

public function configureOptions(OptionsResolver $resolver)
        'validation_groups' => ['registration'],

In both of these cases, only the registration validation group will be used to validate the underlying object. To apply the registration group and all constraints that are not in a group, use:

'validation_groups' => ['Default', 'registration']

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