我正在使用validate.js
来验证我的注册表单。它适用于所有其他字段,但我不明白为什么它不会影响email
字段。
这是我的验证脚本:
<script TYPE="text/javascript">
$(document).ready(function(){
$("#signup").validate({
errorElement: 'div',
rules:{
"display_name":{
required: true,
minlength: 5
},
"user_email":{
required:true,
email: true,
remote: {
url: "user/checkEmail.php",
type: "post"
}
},
"password":{
required:true,
minlength:6
},
"confirm_password":{
required:true,
equalTo: "#password"
}
},
messages: {
display_name:{
required: "Please provide your desired display name",
minlength: "Your display name must be at least 5 characters long"
},
user_email:{
required: "Please provide a valid email",
email: "This is not a valid email!",
remote: "Email already in use!"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 6 characters long"
},
confirm_password: {
required: "Please provide a confirm password",
equalTo: "Please enter the same password as above"
}
}
});
});
</script>
我尝试过不同的方法让它发挥作用,但事实并非如此。 这是我的表格:
<form class="form-horizontal" NAME="signup" id="signup" method="post" ACTION="users/register_submit.php" enctype="multipart/form-data">
<fieldset>
<!-- Form Name -->
<legend>Sign Up</legend>
<!-- Text input-->
<DIV class="form-group">
<label class="col-md-4 control-label" FOR="name">Display Name</label>
<DIV class="col-md-6">
<input id="display_name" NAME="display_name" TYPE="text" placeholder="" class="form-control input-md" required>
</DIV>
</DIV>
<!-- Text input-->
<DIV class="form-group">
<label class="col-md-4 control-label" FOR="email">Email</label>
<DIV class="col-md-6">
<input id="email" NAME="user_email" TYPE="email" placeholder="example@abc.com" class="form-control input-md" required>
</DIV>
</DIV>
<!-- Password input-->
<DIV class="form-group">
<label class="col-md-4 control-label" FOR="password">Password</label>
<DIV class="col-md-6">
<input id="password" NAME="password" TYPE="password" class="form-control input-md" required>
<span class="help-block">At least 6 characters</span>
</DIV>
</DIV>
<!-- Confirm-Password input-->
<DIV class="form-group">
<label class="col-md-4 control-label" FOR="confirm_password">Confirm Password</label>
<DIV class="col-md-6">
<input id="confirm_password" NAME="confirm_password" TYPE="password" placeholder="" class="form-control input-md" required>
</DIV>
</DIV>
<!-- Button -->
<DIV class="form-group">
<label class="col-md-4 control-label" FOR="submit"></label>
<DIV class="col-md-4">
<input id="submit" NAME="submit" TYPE="submit" class="btn btn-primary">
</DIV>
</DIV>
</fieldset>
</form>
请帮帮我。 感谢
修改-UPDATE
这是我的checkEmail.php
代码。我已经测试了它,如果我单独测试它就可以了。
<?php
require_once("../app/utilities/DatabaseUtility.php");
require_once("../app/helpers/DatabaseHelper.php");
function isEmailExists($email){
$res = array();
$db = new DatabaseUtility('apex');
$dbh = new DatabaseHelper;
$db->connect();
$col_array = array("user_email");
$values = array($email);
if( $statment = $db->prepareStatment('SELECT '.$dbh->getColumns($col_array).' FROM users where user_email = '.$dbh->getPlaceHolders($col_array).'')){
$db->bindParam($statment, $dbh->getPlaceHoldersArray($dbh->getPlaceHolders($col_array)), $values, $dbh->getBindTypes($values));
$statment->execute();
$res = $statment->fetch();
if(!empty($res)){
if(in_array($email,$res)){
echo "false";
}
else
echo "true";
}
else
echo "true";
}
else
echo "Someting is wrong with your query";
$db->releaseResources();
}
$requestedEmail = $_REQUEST['email'];
isEmailExists($requestedEmail);
?>
答案 0 :(得分:1)
将电子邮件输入的ID更改为:user_email
编辑:我做了一个小提琴:https://jsfiddle.net/66oxokta/似乎工作正常。究竟什么不适用于您的解决方案?
user_email:{
required: "this works",
email: "this also works",
remote: "didnt test this"
},