0

除了当我在服务器上运行完全相同的脚本时它工作正常之外,没有什么要添加的。验证适用于出现错误以及提交表单的情况。然而,为了方便起见,我有时会通过 xampp、localhost 来处理该项目。问题是 submitHandler 根本没有触发。这不是验证插件设置不正确的情况,否则错误将不起作用。我已经附上了下面的代码

 function registerpage(){
        //******** Registration page functions *******//



    $("#dob").datepicker({dateFormat:"dd/mm/yy"}); // date picker plugin


    $("#register_form").validate({
            errorClass : "invalid",
            invalidHandler:function(event, validator) {$('html, body').animate({scrollTop: '0px'}, 300);},
            submitHandler: registeruser,
            onfocusout: false,
            onkeyup: false,
            onclick: false,
            rules: {
                    firstname: {
                        required : true
                    },
                    lastname: {
                        required : true
                    },
                    email:{
                        required: true, 
                        email: true,
                        remote: { 
                            url: "/actions/emailcheck.php",
                            async: false,
                            type: "post"
                        }
                    },
                    password:{
                        required:true, 
                        minlength: 5    
                    },
                    repeat:{
                        required: true, 
                        equalTo: "#password" 
                    },
                    postcode:{
                        required: true,
                        number: true,
                        minlength: 4
                    },
                    "sport[]":{
                        required: true
                    },
                    dob : {
                        required: true,
                        date: true  
                    }          
                    },
            messages : {
                firstname: {
                    required : "Enter your first name"
                },
                lastname: {
                    required : "Enter your last name"
                },
                email:{
                    required: "Enter your email",   
                    email:"Enter a valid email",
                    remote: "Email already in use"
                },
                password:{
                    required:"Enter a password", minlength: "Password must be 5 characters long"    
                },
                repeat:{
                    required: "Enter a confirmation password", equalTo: "Repeated password does not match" 

                },
                postcode:{
                    required: "Enter postcode",
                    number: "Post code must be 4 digit number", 
                    minlength: "Post code must be 4 digit number"
                },
                dob:{
                    required: "Enter date of birth",    
                    date: "Enter valid date of birth"
                },
                "sport[]": {
                    required: "Select at least one sport"           
                }

            },

            errorContainer: $(".errorCont"), 
            errorLabelContainer: $('.errorCont ul'),
            wrapper: 'li'

    });




        /*Add user to database*/
        function registeruser(){
        //  submit user
                    disablebtn($("#regbtn"));
                    var frmsrl = $("#register_form").serialize();
                    $.post('actions/action.php',frmsrl, 
                    function(data){
                        //successfully registered
                            showpopup("reg");

                        });
        }

    }

真的很困惑为什么它可以在服务器上运行但不能在本地主机上运行。只是 submitHandler 没有被调用,因为错误工作正常。

4

0 回答 0