Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version
WARNING: You are browsing the documentation for Symfony 2.7 which is not maintained anymore. Consider upgrading your projects to Symfony 5.1.

How to Define the Validation Groups to Use

How to Define the Validation Groups to Use

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

$form = $this->createFormBuilder($users, array(
    'validation_groups' => array('registration'),

New in version 2.7: The configureOptions() method was introduced in Symfony 2.7. Previously, the method was called setDefaultOptions().

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' => 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.