I am using jQuery validator for validation the form.I am checking the email id is already exist or not in the database which is working perfectly. I am getting output in the Network->Response tab.
The issue is I am not able to display that validation error message in the form. I also set the message rule but that is not displaying.
Would you help me out in this?
Check below image.

Form
<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/[email protected]/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();
}
}