@@ -535,3 +535,33 @@ after the sport is selected. This should be handled by making an AJAX call
535
535
back to your application. In that controller, you can submit your form, but
536
536
instead of processing it, simply use the submitted form to render the updated
537
537
fields. The response from the AJAX call can then be used to update the view.
538
+
539
+ .. _cookbook-dynamic-form-modification-supressing-form-validation :
540
+
541
+ Supressing Form Validation
542
+ ---------------------------
543
+
544
+ One way you can use ``POST_SUBMIT `` event is to completely supress
545
+ form validation. The reason for that is even if you set ``group_validation ``
546
+ to ``false `` there still some integrity check are run, for example whether
547
+ an uploaded file was too large or whether non-existing fields were submitted.
548
+
549
+ If you want to suppress even that, you should use ``POST_SUBMIT `` event to prevent
550
+ :class: `Symfony\\ Component\\ Form\\ Extension\\ Validator\\ EventListener\\ ValidationListener `
551
+ invocation::
552
+
553
+ use Symfony\Component\Form\FormBuilderInterface;
554
+ use Symfony\Component\Form\FormEvents;
555
+
556
+ public function buildForm(FormBuilderInterface $builder, array $options)
557
+ {
558
+ $builder->addEventListener(FormEvents::POST_SUBMIT, function($event) {
559
+ $event->stopPropagation();
560
+ }, /* priority higher than ValidationListener */ 200);
561
+
562
+ // ...
563
+ }
564
+
565
+ Note that that by doing that you can disable something more than form validation,
566
+ because ``POST_SUBMIT `` event can be used for something else.
567
+ You also have to know what would be the right priority for disabling POST_SUBMIT events.
0 commit comments