Yasir
Yasir

Reputation: 3907

send ajax request after successfull validation using jquery validate plugin

I am using jquery plugin validation for form validation I have a simple question which I couldn't figure out.

$(document).ready(function () {
    $("#contactForm").validate({
        rules: {
            contactName: "Please Enter Full Name",
            contactBody: "Please Enter full message here",
            contactEmail: {
                required: true,
                email: true
            }
        }
    });
});

This validates perfect, what I need is if it is successful than send ajax request or mail to the user otherwise don't.

I know how to send mail using jquery but I need to send it on successful, how ? even I am unable to use alert it gives me bracket } missing error

Upvotes: 0

Views: 2147

Answers (1)

jonstjohn
jonstjohn

Reputation: 60266

You could intercept the submit by using the submitHandler option. This option can be set to a callback function that could fire off an ajax request that sends an email.

To make this work, you will need to setup a script on the server that handles the mail sending. Send all of the data required in the ajax request and the server script can send the mail and return a success response.

Upvotes: 2

Related Questions