Sunday, 11 August 2013

JQuery remote validation not working

JQuery remote validation not working

I had a registration form which i added a JQuery validate plugin remote
validation in. The purpose of the remote validation is to check if the
email/and username entered by the user already exists in my database(i.e
is already in use), and will return an error message if it is.The form was
working before i added the remote validation.
Now, i am unable to submit the form even when all the data i've entered is
correct, and to add insult to injury, no error messages appear when i
enter an email that already exists in my database.
My JQuery code:
$(document).ready(function(){
<!--AJAX Call to retrieve type & subtype of industries-->
$("#type").load("getregtype.php");
$('#type').change(function(){
var type=$('#type').val();
$('#subtype').load('getregsubtype.php?type='+type);
});
<!--End of AJAX Call -->
<!--JQuery validation of registration form-->
<!--Set default message for 'equalTo' errors-->
$.extend($.validator.messages, { equalTo: "The values you entered do not
match." });
$("#regform").validate({
// Specify the validation rules
rules: {
username: "required",
password: {
required:true,
minlength:6,
},
cpassword: {
required: true,
minlength: 6,
equalTo: "#password"
},
email: {
required: true,
email: true,
remote:"emailcheck.php"
},
cemail: {
required: true,
email: true,
equalTo:"#email"
},
type: {
required: true
},
subtype: {
required: true
},
name: "required"
},
// Specify the validation error messages
messages: {
username: "Please enter a username",
email: {
required:"Please enter an email address",
email:"Please enter a valid email address",
remote:jQuery.format("{0} is already in use")
},
cemail: {
required:"Please enter an email address",
email:"Please reenter your email address",
},
password: {
required: "Please enter a password",
minlength: "Your password must be at least 6 characters long"
},
cpassword: {
required:"Please reenter your password",
minlength: "Your password must be at least 6 characters long"
},
name: "Please enter the name of your business"
},
submitHandler: function(form) {
form.submit();
}
});
});
My PHP page that is called by remote.
<?php
include("cxn.inc");
$query=$cxn->prepare("SELECT * FROM `testdb`.`business` WHERE `Email` =
:email");
$query->bindValue(":email",$_GET['email']);
$query->execute();
$count=$query->rowCount();
$mail=$_GET['email'];
print_r($mail);
echo"$count";
if($count>0)
{
echo json_encode('false');
}
else
{
echo json_encode('true');
}
?>
Things tried
print_r($mail) and echo"$count"; both return the correct value.I've also
tried
echo json_encode(true);
as well as
return true;
EDIT
Some more things i've tried.
echo true;
I've also tried to pass in the value of the email directly through the
url, on the off chance that the value was not being passed to
'emailcheck.php' by doing
email: {
required: true,
email: true,
remote:"emailcheck.php?email=test@test.com"
},
but my form still doesn't work.
I appreciate any insight to my problem.
Thanks!

No comments:

Post a Comment