jQuery Validate Remote Email Validation not working
In my user editor page, I'm trying to check if a enter email is in use by other customers but not the customers current email. This is my code, it doesn't seem to show an error message, but my form is unable to submit.
Here is my JS:
$("#cedit").validate({
rules : {
email : {
email : true,
remote : {
url : "ajax_checkemail.php",
type : "GET",
data : {
email : function() {
return $("#email").val();
},
custid : function() {
return $("#editc").val();
}
}
}
}
},
messages : {
email : {
remote : "Email is in use"
}
}
});
And the PHP
include 'common.ph开发者_开发知识库p';
$valid = false;
if(isset($_GET['email']))
{
$email = $_GET['email'];
$query = "SELECT * FROM `customer` WHERE `email_address` = '$email'";
if(isset($_GET['custid']) && !empty($_GET['custid']))
{
$custid = $_GET['custid'];
$query .= " AND `customer_id` != '$custid'";
}
$result = query($query);
$count = mysql_num_rows($result);
if ($count == 0)
{
$valid = true;
}
}
echo json_encode($valid);
The PHP works fine when i access it directly and put the GET parameters in the URL, but for some reason it won't validate properly and thus won't let the form submit.
I never used this remote validation, but don't you need to set the response type to json in your php script? As in header('Content-type: application/json');
精彩评论