2

I have the following code, validation works fine, but it doesnt submit

jQuery("#form_driver").validate({
    submitHandler: function(form) {
    //check if email exists
    jQuery.ajax({
                type: "POST",
                url: "checkmail.php",
                data: ({
                    email: jQuery("#email").val()
                }),
                cache: false,
                success: function(data)
                {
                   
                    if(data == 0) {
                        alert("Email doesnt exist");
                        return false;
                    }else if (data==1){
                        alert("The Email is already linked to your location!");
                        return false;
                    }else if (data==2){
                        jQuery("#form_driver").submit();
                        return true;
                    }
                }
            });
    }
});

Unbelievable what it outputs to the console, Its driving me crazy, it iterates forever, I had to stop it manually

enter image description here

Community
  • 1
  • 1
Digital fortress
  • 737
  • 8
  • 18
  • 31
  • Did you try without this part: `jQuery("#form_driver").submit();` ? - its just re-starting the validation, or? – Sergio Sep 07 '13 at 22:00
  • @Sergio I just did, one good thing that it stopped iterating the console output, just gave me a 2 once, but still didn't submit! – Digital fortress Sep 07 '13 at 22:10

1 Answers1

2

You need to submit the form passed to the submitHandler. You are reselecting the form via jQuery instead. See the api.

Try this instead:

jQuery("#form_driver").validate({
    submitHandler: function(form) {
    //check if email exists
    jQuery.ajax({
                type: "POST",
                url: "checkmail.php",
                data: ({
                    email: jQuery("#email").val()
                }),
                cache: false,
                success: function(data)
                {

                    if(data == 0) {
                        alert("Email doesnt exist");
                        return false;
                    }else if (data==1){
                        alert("The Email is already linked to your location!");
                        return false;
                    }else if (data==2){
                        form.submit();
                        return true;
                    }
                }
            });
    }
});
Kyle Weller
  • 2,533
  • 9
  • 35
  • 45