0

When I'm developing I don't always want to validate my forms via Symfony2's validator.

(I'm not talking about turning off HTML5 validation.)

Is there a quick way to disable and re-enable form validation?

Tek
  • 2,888
  • 5
  • 45
  • 73

2 Answers2

2

For this, you can set the validation_groups option to false:

use Symfony\Component\OptionsResolver\OptionsResolverInterface;

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'validation_groups' => false,
    ));
}

Hope this will work.

These links will help: temporarily disabling validation

Skip validation if sibling (checkbox) field contains 'false'

Community
  • 1
  • 1
Krupal Shah
  • 8,949
  • 11
  • 57
  • 93
  • Hmm, I'm using a lot of forms so I'd have to do this to every single one... I'll try to see if this is worth the effort though, thanks for your suggestion. – Tek Jul 15 '14 at 14:56
  • @Tek thanks...see the link in edited answer...it may help you – Krupal Shah Jul 15 '14 at 14:59
  • That last link is very interesting. I'm just wondering how I can use it to my advantage... Maybe I'll inject that option into the construct of all my forms and to validate by default but have an option to manually turn validation off in the constructor options. I think that will work, thanks! – Tek Jul 15 '14 at 15:06
  • By the way, you should change your username to something nicer. http://stackoverflow.com/users/edit/3830694 :) – Tek Jul 15 '14 at 15:09
  • First link to documentation isn't right anymore. Correct link: http://symfony.com/doc/current/form/disabling_validation.html – Juuuuuu Dec 12 '16 at 13:59
-1

try this

you can handle this using jquery

for disable form validation?

$(fromId).removeAttr("novalidate");

and

for remove form validation?

$(fromId).attr("novalidate");

Amol Shiledar
  • 367
  • 4
  • 12