Zend表单过滤器和Ajax

时间:2014-08-07 20:47:57

标签: php jquery ajax zend-framework2

Havin a Zf2注册表和一个电子邮件过滤器是这样的:

array(
     'name'    => 'Db\NoRecordExists',
     'options' => array(
         'table' => 'user',
         'field' => 'email',
         'adapter' =>  $sm->get ( 'Zend\Db\Adapter\Adapter' ),
         'messages' => array(
              NoRecordExists::ERROR_RECORD_FOUND => 'E-mail address already exists'
         ),
      ),
),

此验证程序检查电子邮件地址是否已存在。它工作正常,但当我尝试用jQuery连接我的项目时:

$( document ).ready(function() {
    $("#btnRegister").click( function() {

        $("#email").css("border-color", "");
        $("#password").css("border-color", "");
        $("#confirm_password").css("border-color", "");
        $("#emailReg").text("");
        $("#passwordReg").text("");

        var email = $("#email").val();
        var password = $("#password").val();
        var confirm_password = $("#confirm_password").val();
        $("#Register").submit( function() {
           return false;    
        });
        if((/([\w\-]+\@[\w\-]+\.[\w\-]+)/.test(email)) != true) {
            $("#email").css("border-color", "red");
            $("#emailReg").text("Invalid email format");
        } else if(password.length < 6) {
            $("#password").css("border-color", "red");
            $("#passwordReg").text("Password must be at least 6 characters long");
        } else if ((password == confirm_password) != true) {
            $("#password").css("border-color", "red");
            $("#confirm_password").css("border-color", "red");
            $("#passwordReg").text("Password doesn't match");
        } else if((/((?=.*[0-9])(?=.*[A-Z]))/gm.test(password)) != true) {
            $("#password").css("border-color", "red");
            $("#passwordReg").text("Password must contian at least one digit and upper case");
        }   else  { 
            $.post( 
            $("#Register").attr("action"),
            $("#Register :input").serializeArray());
            location.href = "auth";
        }   
    });
});

此文件检查电子邮件的正确格式,还有一些密码验证器,当所有这些都正确时,它会重定向到auth页面,它应该将用户注册到DB中。但它不会让zf模块的动作将数据插入db。任何想法如何解决这个问题?

0 个答案:

没有答案