Skip to content

Commit 89ab51e

Browse files
committed
bug #8940 Reworded the note about supressing form validation (javiereguiluz)
This PR was merged into the 2.7 branch. Discussion ---------- Reworded the note about supressing form validation This replaces #6461 according to reviewer's comments. @HeahDude please check if this PR is correct according to your comment here: #6461 (comment) Commits ------- cb823f7 Reworded the note about supressing form validation
2 parents 0f791e6 + cb823f7 commit 89ab51e

File tree

1 file changed

+2
-27
lines changed

1 file changed

+2
-27
lines changed

form/dynamic_form_modification.rst

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -710,30 +710,5 @@ code from above to generate the submitted form can be reused.
710710
Suppressing Form Validation
711711
---------------------------
712712

713-
To suppress form validation you can use the ``POST_SUBMIT`` event and prevent
714-
the :class:`Symfony\\Component\\Form\\Extension\\Validator\\EventListener\\ValidationListener`
715-
from being called.
716-
717-
The reason for needing to do this is that even if you set ``validation_groups``
718-
to ``false`` there are still some integrity checks executed. For example
719-
an uploaded file will still be checked to see if it is too large and the form
720-
will still check to see if non-existing fields were submitted. To disable
721-
all of this, use a listener::
722-
723-
use Symfony\Component\Form\FormBuilderInterface;
724-
use Symfony\Component\Form\FormEvents;
725-
use Symfony\Component\Form\FormEvent;
726-
727-
public function buildForm(FormBuilderInterface $builder, array $options)
728-
{
729-
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
730-
$event->stopPropagation();
731-
}, 900); // Always set a higher priority than ValidationListener
732-
733-
// ...
734-
}
735-
736-
.. caution::
737-
738-
By doing this, you may accidentally disable something more than just form
739-
validation, since the ``POST_SUBMIT`` event may have other listeners.
713+
To suppress form validation, set ``validation_groups`` to ``false`` or an empty
714+
array.

0 commit comments

Comments
 (0)