jQuery Validate远程重定向页面为false [英] jQuery Validate Remote redirect page on false

查看:78
本文介绍了jQuery Validate远程重定向页面为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Validate remote检查php文件,并查看电子邮件地址是否已在使用中.它可以正常工作,但是,如果键入的电子邮件已经存在或为"false",则我需要将其重定向到新页面.以下是有效的远程验证脚本和简单的php文件.再次可以正常工作,只是不确定如果php脚本返回false时如何重定向到新页面.

I am using jQuery Validate remote to check a php file and see if an email address is already in use. It works fine, however, I need it to redirect to a new page IF the email typed in already exists or "false". Below is the working remote validate script and simple php file. Again this works fine, just not sure how to redirect to a new page if the php script returns false.

     rules: {
            fullname: "required",
            email: {
                required: true,
                email: true,
                remote: {
                    url: "validate-email.php",
                    type: "post",
                },
            },

    messages: {
     email: {
        required: 'Please enter a valid email address',
        remote: 'Sorry, this email address is already in use',
        }
    }

validate-email.php

validate-email.php

$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$prep_stmt = "SELECT id FROM members WHERE email = ? LIMIT 1";
$stmt = $mysqli->prepare($prep_stmt);

if ($stmt) {
    $stmt->bind_param('s', $email);
    $stmt->execute();
    $stmt->store_result();

    if ($stmt->num_rows == 1) {
        // A user with this email address already exists
        echo 'false';
    }else{
        echo 'true';
    }
}

最后一次提到它,上面的php和jquery脚本工作正常.如果php结果为echo'false',只需重定向到新页面;

Just to mention it one last time, the above php and jquery script work fine. Just need to redirect to a new page if the php result is echo 'false';

推荐答案

我能够通过简单地添加TheMintyMate中的信息进行重定向

I was able to redirect by simply adding the information from TheMintyMate

 rules: {
        fullname: "required",
        email: {
            required: true,
            email: true,
            remote: {
                url: "validate-email.php",
                type: "post",
                success: function(e) { if(e == false){window.location.replace("http://website");}}
            },
        },

messages: {
 email: {
    required: 'Please enter a valid email address',
    remote: 'Sorry, this email address is already in use',
    }
}

这篇关于jQuery Validate远程重定向页面为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆