How to call validationEngine with $ .ajax submit?

I am using a built-in function to submit a form, but it does not trigger the validation script I have, and I was wondering if someone could point me in the right direction of the answer?

My button:

<a href="javascript:UpdateEnquiry();" id="continue_btn" class="btnSprite">Save</a>

      

My function:

function UpdateEnquiry() {

$.ajax({
  url: 'test.php',
  dataType: 'xml',
  timeout: 15000,
  type: 'post',
  data: $('#validate').serialize(),
  success: UpdateEnquirySuccess,
  error: function (result) {parent.$.fancybox.close();}
  });
}

      

And I would like to initialize the jquery validationEngine plugin before submitting. http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/

Any help would be greatly appreciated.

Regards Rachel

+3


source to share


2 answers


Assuming your validator is already initialized, call the method validate

before making the ajax request. If this method returns true

, you continue:



function UpdateEnquiry() {
    if ( $(yourForm).validationEngine('validate') ) {
        $.ajax({
            ...
        });
    }
    else {
        // The form didn't validate
    }

    return false; // Prevents default action from happening
}

      

+4


source


$('#registerform').submit(function(e) {
                e.preventDefault();
                var vars = $("#registerform").serialize();

                if ($("#registerform").validationEngine('validate')) {

                    $.ajax({
                            url:"sample.php"
                    });

                }
            });

      



without stopping the default action, I redirected to the action page of my form. So I had to use preventdefault (). @mgibsonbr my bad

+4


source







All Articles