1

I am trying to have my form validate before the ajax runs but can't seem to get the coding right for this to happen.

if i seperate them i can post using ajax with no validation or validation but it posts the default way

here is my current code i am trying

$(document).ready(function(){
 // ajax code start
$('#form').on('submit', function (e){
    e.preventDefault();
  if  (spry.widget.form.validate('#form') == true)
    {
    $.ajax({
        type: "POST",
        url: "localProxy.php",
        data: $('#form').serialize(),
        success: function (response) {
                document.location = '/thank-you';
                 // do something!
        },
        error: function () {
                alert('There was a problem!');  // handle error
        }
    });
    };
}); 
});

1 Answers1

2

figured it out

$(document).ready(function(){
 // ajax code start
$('#form').on('submit', function (e){
    e.preventDefault();
    Spry.Widget.Form.onSubmit = function(e, form)
{
    if (Spry.Widget.Form.validate(form) == false) {
        return false;
    }
    {
    $.ajax({
        type: "POST",
        url: "localProxy2.php",
        data: $('#consult').serialize(),
        success: function (response) {
                document.location = '/thank-you';
                 // do something!
        },
        error: function () {
                alert('There was a problem!');  // handle error
        }
    });
    };
    };
}); 
});