开发者

Form not submitting using the validationEngine() plugin from Position Absolute

I'm using the validationEngine jQuery plugin to validate my webform. Once the validation completes, I'd like to submit the form via ajax. The form submits fine without the validation engine plugin attached. The validation works, but the ajax is not firing to submit the form after it completes. What am I doing wrong:

jQuery("form#sign-up").validationEngine({
    onValidationComplete: function () {
        var first = $("input#first").val();
        var last = $("input#last").val();
        var email = $("input#email").val();
        var pass = $("input#pass").val();



        var dataString = 'first=' + first + '&last=' + last + '&email=' + email + '&pass=' + pass;

        //to send the ajax request  
        $.ajax({
            type: "POST",
            url: "./register.php",
            data: dataString,
            success: function () {
                $('#sign-up').html("<div id='message'></div>");
                $('#message').html("<h2>Thanks!</h2>")
                    .append("<p>We'll send you an email when infoFree is ready to Rock n' Roll.</p>")
                    .hide()
                    .fadeIn(500, function () {
                    $('#message').append("<img id='checkmark' src='./assets/images/check.png' />");
  开发者_开发问答              });
            }
        });
    }
});


validationengine prevents the form actually submitting, so instead of doing everything inside onValidationComplete, just move it all into a function on submit of the form:

$(document).ready(function() {
  $("form#sign-up").validationEngine();
  $("form#sign-up").submit(function(){
    var first = $("input#first").val();
    var last = $("input#last").val();
    var email = $("input#email").val();
    var pass = $("input#pass").val();

    var dataString = 'first='+ first + '&last=' + last + '&email=' + email + '&pass=' + pass;

    //to send the ajax request  
    $.ajax({
      type: "POST",
      url: "./register.php",
      data: dataString,
      success: function() {
        $('#sign-up').html("<div id='message'></div>");
        $('#message').html("<h2>Thanks!</h2>")
        .append("<p>We'll send you an email when infoFree is ready to Rock n' Roll.</p>")
        .hide()
        .fadeIn(500, function() {
          $('#message').append("<img id='checkmark' src='./assets/images/check.png' />");
        });
      } 
    });
  });
}); // ready

~Cyrix

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜