File tree Expand file tree Collapse file tree 2 files changed +213
-125
lines changed Expand file tree Collapse file tree 2 files changed +213
-125
lines changed Original file line number Diff line number Diff line change @@ -348,6 +348,31 @@ corresponding errors printed out with the form.
348
348
Validation is a very powerful feature of Symfony2 and has its own
349
349
:doc: `dedicated chapter</book/validation> `.
350
350
351
+ .. _book-forms-validation-groups :
352
+
353
+ Validation Groups
354
+ ~~~~~~~~~~~~~~~~~
355
+
356
+ If your object takes advantage of :ref: `validation groups <book-validation-validation-groups >`,
357
+ you'll need to specify which validation group(s) your form should use::
358
+
359
+ $form = $this->createFormBuilder($user)
360
+ ->setAttribute('validation_groups', array('registration'))
361
+ // ...
362
+ ;
363
+
364
+ If you're creating :ref: `form classes<book-form-creating-form-classes> ` (a good
365
+ practice), then you'll need to add the following to the ``buildForm() `` method::
366
+
367
+ public function buildForm(FormBuilder $builder, array $options)
368
+ {
369
+ // Restrict the constraints to the 'registration' group
370
+ $builder->setAttribute('validation_groups', array('registration'));
371
+ }
372
+
373
+ In both of these cases, *only * the ``registration `` validation group will
374
+ be used to validate the underlying object.
375
+
351
376
.. index ::
352
377
single: Forms; Built-in Field Types
353
378
@@ -591,6 +616,8 @@ available in the :doc:`reference manual</reference/forms/twig_reference>`.
591
616
.. index ::
592
617
single: Forms; Creating form classes
593
618
619
+ .. _book-form-creating-form-classes :
620
+
594
621
Creating Form Classes
595
622
---------------------
596
623
You can’t perform that action at this time.
0 commit comments