José Neto
José Neto

Reputation: 3

Why my form need two (2) clicks to submit using jQuery Validate?

Why my form need two clicks to submit using jQuery Validate?

contact_form.validate({ ... });

Demo: http://goo.gl/7jQjqY

Please help! Thanks!

Upvotes: 0

Views: 923

Answers (1)

Shai
Shai

Reputation: 7317

Calling

$(form).submit(function() {
   //
});

inside your submitHandler is incorrect: you are just adding the supplied function as an event handler for the form, but not actually calling it. So the first time you press the button, you are only defining a new event handler. The second press works because now that handler has been defined.

To fix, just remove the

$(form).submit(function() {

and corresponding

});

lines, putting your submit code directly in the submitHandler instead.

submitHandler: function(form) {
    var str = $(this).serialize();

    $.ajax({
        url: 'process.mail.jsp',
        type : 'POST',
        data: str,
        //dataType : 'json',
        success: function(result) {
            // etc
        }
    });
}

Working example here – it's literally just yours with lines 37 and 57 commented out.

Upvotes: 1

Related Questions