Jquery Validation Message Not Displaying While Checking The Email Exist Or Not
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 Networ
Solution 1:
Try this:-
$(function() {
$("form[name='form1']").validate({
// Specify the validation rulesrules: {
name:{
required: true,
minlength: 3,
maxlength: 50
},
email: {
required: true,
email: true,
remote: "process?key=emailalready_register",
},
mobile: {
required: true,
number: true,
minlength: 10,
maxlength: 10
}
},
messages: {
email: {remote: "Email already in use!"}
},
submitHandler: function(form) {
form.submit();
}
});
});
Process .php
functionemailalready_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'false';
} else {
echo'true';
}
$stmt->close();
$conn->close();
}
}
Solution 2:
Solution 3:
You can put a div in your html
and target to output the message, like so:
<divclass="messages"></div>
Solution 4:
Note: The url given in your email check is wrong.
Change your test.js to this:
$(function() {
$("form[name='form1']").validate({
// Specify the validation rulesrules: {
name:{
required: true,
minlength: 3,
maxlength: 50
},
email: {
required: true,
email: true,
remote: {
url: "process.php",
type: "post",
dataFilter: function(data) {
var json = JSON.parse(data);
return"\"" + json.msg + "\"";
}
}
},
mobile: {
required: true,
number: true,
minlength: 10,
maxlength: 10
}
},
messages: {
email: {remote: "email is in use!"}
},
submitHandler: function(form) {
form.submit();
}
});
});
Change your process.php to this:
<?php
/* if(isset($_POST['email'])) {
//make your $conn available here
$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 json_encode(array("msg"=>"Already exists"));
} else {
echo json_encode(array("msg"=>"Not exists"));
}
$stmt->close();
$conn->close();
}
*/
echo json_encode(array("msg"=>"Already exists"));
Note: this is for demo of the message so it will always show "Already exists"
. comment the last line and un-comment the rest of process.php and check.Please look for the process.php code and check if it is working properly or not.
Post a Comment for "Jquery Validation Message Not Displaying While Checking The Email Exist Or Not"