Ajax远程验证wordpress用户名和电子邮件与Jquery验证

时间:2014-10-29 04:50:01

标签: jquery ajax wordpress

我正在尝试实施以下

Ajax remote validate wordpress username and email with Jquery validation plugin

解决方案显示正确的消息,但它不允许提交表单,因为无论输入是否有效,它都会添加错误类。

请帮我弄清楚。

JQuery验证码:

$("#sign-up-form form").validate({
                rules: {
                   "log": {
                        required: true,
                        remote: {
                                url: '<?php echo get_bloginfo('url'); ?>/wp-admin/admin-ajax.php',
                                type: "post",
                                data: {
                                   'user_email': function() {
                                        return $( "#log" ).val();
                                    },
                                   'action': 'check_user_name'
                                }

                            }
                    },
                    "user_email": {
                        required: true,
                        email: true,
                          remote: {
                                url: '<?php echo get_bloginfo('url'); ?>/wp-admin/admin-ajax.php',
                                type: "post",
                                data: {
                                   'user_email': function() {
                                        return $( "#user_email" ).val();
                                    },
                                   'action': 'check_user_email'

                                }
                            }
                    },  
                    "phone1": {
                        required: true,
                        number: true,
                        minlength: 5
                    } 
                }
});

Wordpress功能:

add_action( 'wp_ajax_nopriv_check_user_email', 'check_user_email_callback' );
function check_user_email_callback() {
global $wpdb; // this is how you get access to the database
if(email_exists($_POST['user_email'])){
    echo json_encode('Already registered');
}
else{
    echo json_encode('true');
}
die();
}

add_action( 'wp_ajax_nopriv_check_user_name', 'check_user_name_callback' );
function check_user_name_callback() {
global $wpdb; // this is how you get access to the database
if(username_exists($_POST['log'])){
    echo json_encode('Already taken');
}
die();
}

0 个答案:

没有答案