diff --git a/book/forms.rst b/book/forms.rst index a861d232997..0998408312e 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -504,6 +504,8 @@ fields were submitted. If you want to suppress validation, you can use the .. index:: single: Forms; Validation groups based on submitted data +.. _book-form-validation-groups: + Groups based on the Submitted Data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/reference/forms/types/submit.rst b/reference/forms/types/submit.rst index 72faa779ae1..01847034d84 100644 --- a/reference/forms/types/submit.rst +++ b/reference/forms/types/submit.rst @@ -17,6 +17,7 @@ A submit button. | | - `label`_ | | | - `label_attr`_ | | | - `translation_domain`_ | +| | - `validation_groups`_ | +----------------------+----------------------------------------------------------------------+ | Parent type | :doc:`button` | +----------------------+----------------------------------------------------------------------+ @@ -45,6 +46,33 @@ Inherited Options .. include:: /reference/forms/types/options/button_translation_domain.rst.inc +validation_groups +~~~~~~~~~~~~~~~~~ + +**type**: ``array`` **default**: ``null`` + +When your form contains multiple submit buttons, you can change the validation +group based on the button which was used to submit the form. Imagine a registration +form wizard with buttons to go to the previous or the next step:: + + $form = $this->createFormBuilder($user) + ->add('previousStep', 'submit', array( + 'validation_groups' => false, + )) + ->add('nextStep', 'submit', array( + 'validation_groups' => array('Registration'), + )) + ->getForm(); + +The special ``false`` ensures that no validation is performed when the previous +step button is clicked. When the second button is clicked, all constraints +from the "Registration" are validated. + +.. seealso:: + + You can read more about this in :ref:`the Form chapter ` + of the book. + Form Variables --------------