2

Ok so I have a form that I am validating with jQuery Validation and I am trying to now submit it with AJAX. With the code below, once the form is valid and you click on submit the page reloads and the inputs are placed in the url address bar (i.e. method="get")

In the ajax method I have that set to POST but it doesn't appear to be using the ajax call.

What did I do wrong?

$().ready(function() {
    var $form = $(this);
   //validate the inquiry form on keyup and submit
    $("#inquiryForm").validate({
        showErrors: function(errorMap, errorList) {
            for (var error in errorMap)  {
                $.growl.error({ message: errorMap[error] });
             }
        },
        onkeyup: false,
        rules: {
            fullName: {
                required: true
            },
            email: {
                required: true,
                email: true
            },
            inquiry: {
                required: true,
                minlength: 5,
                maxlength: 500
            }
        },
        messages: {
            fullName: "Your name is required",
            email: "A valid email address is required",
            inquiry: "Your inquiry is required and must have between 5-500 characters"
        },

        submitHandler: function(form) {
            $.ajax({
                url: form_submit/inquiry_form/inquiry_form.php,
                type: "POST",
                data: $(form).serialize(),
                success: function(response) {
                    $('#inquiryFormHolder').html("Your form was submitted!");
                }            
            });
            return false;
        }
    });
});
Super User
  • 9,448
  • 3
  • 31
  • 47
Mitch Evans
  • 641
  • 3
  • 10
  • 25

1 Answers1

8

Try to use :

submitHandler: function(form) {
    $.ajax({
        url: form_submit/inquiry_form/inquiry_form.php,
        type: "POST",
        data: $(form).serialize(),
        success: function(response) {
            $('#inquiryFormHolder').html("Your form was submitted!");
        }            
    });
    $form.submit();
}
Super User
  • 9,448
  • 3
  • 31
  • 47
Fouad Fodail
  • 2,653
  • 1
  • 16
  • 16