From cb823f73c8432fc8d5d3bd9e4a966458880ca72a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 29 Dec 2017 08:54:55 +0100 Subject: [PATCH] Reworded the note about supressing form validation --- form/dynamic_form_modification.rst | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/form/dynamic_form_modification.rst b/form/dynamic_form_modification.rst index 8fcc76fd07a..42ad85ded26 100644 --- a/form/dynamic_form_modification.rst +++ b/form/dynamic_form_modification.rst @@ -710,30 +710,5 @@ code from above to generate the submitted form can be reused. Suppressing Form Validation --------------------------- -To suppress form validation you can use the ``POST_SUBMIT`` event and prevent -the :class:`Symfony\\Component\\Form\\Extension\\Validator\\EventListener\\ValidationListener` -from being called. - -The reason for needing to do this is that even if you set ``validation_groups`` -to ``false`` there are still some integrity checks executed. For example -an uploaded file will still be checked to see if it is too large and the form -will still check to see if non-existing fields were submitted. To disable -all of this, use a listener:: - - use Symfony\Component\Form\FormBuilderInterface; - use Symfony\Component\Form\FormEvents; - use Symfony\Component\Form\FormEvent; - - public function buildForm(FormBuilderInterface $builder, array $options) - { - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { - $event->stopPropagation(); - }, 900); // Always set a higher priority than ValidationListener - - // ... - } - -.. caution:: - - By doing this, you may accidentally disable something more than just form - validation, since the ``POST_SUBMIT`` event may have other listeners. +To suppress form validation, set ``validation_groups`` to ``false`` or an empty +array.