【发布时间】:2018-03-14 03:42:11
【问题描述】:
我正在使用 jQuery 验证器来验证表单。我正在检查电子邮件 ID 是否已存在于运行正常的数据库中。我在Network->Response tab 中得到输出。
问题是我无法在表单中显示该验证错误消息。我也设置了消息规则,但没有显示。
表格
<form name="form1" method="post" action="demo1.php">
<input type="text" name="name" id="name" placeholder="name"><br />
<input type="email" name="email" id="email" placeholder="email"><br />
<input type="text" name="mobile" id="mobile" placeholder="mobile no"><br />
<input type="submit" name="submit" value="submit">
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.17.0/dist/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/additional-methods.min.js"></script>
<script src="assets/js/test.js"></script>
test.js
// When the browser is ready...
$(function() {
$("form[name='form1']").validate({
// Specify the validation rules
rules: {
name:{
required: true,
minlength: 3,
maxlength: 50
},
email: {
required: true,
email: true,
remote: {
url: "process?key=emailalready_register",
type: "post"
}
},
mobile: {
required: true,
number: true,
minlength: 10,
maxlength: 10
}
},
messages: {
email: {remote: "Email already in use!"}
},
submitHandler: function(form) {
form.submit();
}
});
});
Process.php
function emailalready_register($conn){
if(isset($_POST['email'])) {
$email =$conn->real_escape_string(trim($_POST['email']));
$sql_check_email="SELECT email FROM register WHERE email =?";
$stmt = $conn->prepare($sql_check_email);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($email);
$rows = $stmt->fetch();
$total_rows = count($rows);
if( $total_rows > 0 ){
echo 'Already exsist';
} else {
echo 'Not exsist';
}
$stmt->close();
$conn->close();
}
}
【问题讨论】:
标签: javascript php jquery validation