[英]jQuery Validate Remote redirect page on false
我正在使用jQuery Validate remote检查php文件,并查看电子邮件地址是否已在使用中。 它工作正常,但是,如果键入的电子邮件已经存在或为“ false”,则我需要它重定向到新页面。 以下是有效的远程验证脚本和简单的php文件。 再次可以正常工作,只是不确定如果php脚本返回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
$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',则只需重定向到新页面;
我只需通过添加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',
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.