@@ -592,3 +592,33 @@ after the sport is selected. This should be handled by making an AJAX call
592
592
back to your application. In that controller, you can submit your form, but
593
593
instead of processing it, simply use the submitted form to render the updated
594
594
fields. The response from the AJAX call can then be used to update the view.
595
+
596
+ .. _cookbook-dynamic-form-modification-suppressing-form-validation :
597
+
598
+ Suppressing Form Validation
599
+ ---------------------------
600
+
601
+ To suppress form validation you can use the ``POST_SUBMIT `` event and prevent
602
+ :class: `Symfony\\ Component\\ Form\\ Extension\\ Validator\\ EventListener\\ ValidationListener `
603
+ invocation.
604
+
605
+ The reason for this is even if you set ``group_validation `` to ``false `` there
606
+ are still some integrity checks executed, for example whether an uploaded file
607
+ was too large or whether non-existing fields were submitted::
608
+
609
+ use Symfony\Component\Form\FormBuilderInterface;
610
+ use Symfony\Component\Form\FormEvents;
611
+
612
+ public function buildForm(FormBuilderInterface $builder, array $options)
613
+ {
614
+ $builder->addEventListener(FormEvents::POST_SUBMIT, function($event) {
615
+ $event->stopPropagation();
616
+ }, 900); // Always set a higher priority than ValidationListener
617
+
618
+ // ...
619
+ }
620
+
621
+ .. caution ::
622
+
623
+ By doing this, you can disable something more than just form validation,
624
+ because the ``POST_SUBMIT `` event can be used for something else too.
0 commit comments