远程验证

时间:2010-01-21 00:46:31

标签: javascript jquery validation

下面是我的代码,验证仅在没有远程验证的情况下有效。一旦我包含远程验证,它提交表单而不完成所有其他表格验证?

    $(document).ready(function() {


      $("#form1").validate({
            rules: {
                firstName: "required",// simple rule, converted to {required:true}
                lastName: "required",
                email: {// compound rule
                        required: true,
                        email: true,
                        success: "valid",
                        remote: "checkAddress.php"
                },      
                password: {
                    required: true,
                    success: "valid",
                    minlength: 5
                },

                verify: {
                    required: true,
                    success: "valid",
                    minlength: 5,
                    equalTo: "#password"
                },
                address1: "required",
                city: "required",
                province: "required",

                dob: {
                    required: true,
                    date: true,
                    success: "valid"
                },


                captcha_code: {
                    required: true,
                    captcha_code: true,
                    remote: "checkCaptcha.php"      
                }   

            },
            messages: {
               email:{
                   remote: "This email is already registered! One registration per email address."
               },
               captcha_code:{
                  remote: "Enter the right captcha value!."
               }
            },
            onsubmit: true
        });
    });

3 个答案:

答案 0 :(得分:1)

我问的是你是否已经将captcha_code作为一种方法实现了?在captcha_code: true,

 captcha_code: {
      required: true,
      captcha_code: true,
      remote: "checkCaptcha.php"      
 }   

喜欢这个

jQuery.validator.addMethod("captcha_code", function(value, element) {
    return (this.optional(element) || /* do something */ );
}, "");

我发现了这个验证码演示,它没有captcha_code作为方法,只需要和远程。所以我在想你是否已经实现了它。

以下是演示中的脚本。 http://jquery.bassistance.de/validate/demo/captcha/

$(function(){
$("#refreshimg").click(function(){
    $.post('newsession.php');
    $("#captchaimage").load('image_req.php');
    return false;
});

$("#captchaform").validate({
    rules: {
        captcha: {
            required: true,
            remote: "process.php"
        }
    },
    messages: {
        captcha: "Correct captcha is required. Click the captcha to generate a new one" 
    },
    submitHandler: function() {
        alert("Correct captcha!");
    },
    success: function(label) {
        label.addClass("valid").text("Valid captcha!")
    },
    onkeyup: false
});

});

答案 1 :(得分:0)

远程URL被传递到它所期望的JSON TRUE / FALSE字段的值,你是否在这个?

答案 2 :(得分:0)

所以我改变了:

email: {// compound rule
                    required: true,
                    email: true,
                    success: "valid",
                    remote: "checkAddress.php"
            },
captcha_code: {
                required: true,
                captcha_code: true,
                remote: "checkCaptcha.php"      
            }

email: {// compound rule
                    required: true,                  
                    remote: "checkAddress.php"
            },
captcha_code: {
                required: true,
                remote: "checkCaptcha.php"      
            }

它很棒,哇,你们摇滚!!!“