1

I am using a CMS that creates a form and sends it via AJAX. I'd like to validate the inputs before, but cannot prevent it from sending, because the CMS binds sending on the submit event.

bind(form, "submit", function(e){
  …
})

I thought this would stop it and I can validate my inputs.

$( ".contact-form form" ).on('submit', function(e){
  e.stopImmediatePropagation();
})

But even stopImmediatePropagation() won't prevent sending.

suntrop
  • 775
  • 3
  • 10
  • 24

1 Answers1

2

you can try

    $( ".contact-form form" ).on('submit', function(e){
      e.preventDefault();
    })

or

    $( ".contact-form form" ).on('submit', function(e){
      return false;
    })

Here's the difference between the two... event.preventDefault() vs. return false

Hope that helps

Community
  • 1
  • 1
j_buckley
  • 1,926
  • 1
  • 12
  • 13
  • Had both tested and it keeps submitting the form. – suntrop Jun 09 '14 at 19:11
  • Based on the code you posted my next move would be within your bind(form, "submit", function(e){...}) to add something like...if($(this).hasClass("contact-form form")){e.preventDefault;} and remove your on submit event – j_buckley Jun 09 '14 at 19:36
  • That means editing the core files of the CMS. I hoped there is a way to hijack it from my jQuery code. – suntrop Jun 09 '14 at 20:16