Skip to content

Reworded the note about supressing form validation #8940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.