I'm trying to add remote method for check login availability to jquery validation. I have read other questions, but it don't helped me... It's not working. I do not know where I was wrong
$('#contact-form').validate({
rules: {
login: {
required: true,
remote: {
url: "user_availability.php",
type: "post",
data:
{
login: function()
{
return $('#contact-form :input[name="login"]').val();
}
}
}
}
},
messages:{
login:{
required: "Please enter your login.",
remote: jQuery.validator.format("{0} is already taken.")
}
}
});
File user_availability.php :
<?php
$existing_users=array('admin','mike','jason');
$user_name=$_POST['user_name'];
if (in_array($user_name, $existing_users))
{
echo "false"; //already registered
}
else
{
echo "true"; //user name is available
}
?>