I am gonna to test plugin Validation especially method “remote”. I made test example that consists from HTML file with following code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js"></script>
<script>
$(function(){
$('#myForm').validate({
rules:
{
name:
{
required:true,
remote:'nameCheck1.php'
},
email:
{
required:true,
email:true
}
}
});
});
</script>
</head>
<body>
<form action="http://modx.megabulk.ru" method="post" id="myForm">
<input type="text" name="name" placeholder="имя">
<br><br>
<input type="text" name="email" placeholder="e-mail">
<br><br>
<input type="submit">
</form>
</body>
</html>
And PHP file with following code:
<?php
$users = array ("Poul", "Anna", "Malika", "Jack", "Elena");
$newUser = $_POST['name'];
if (in_array($newUser, $users))
{
return false;
}
else
{
return true;
}
?>
And then I began to test my form. In browser console I see the following error:
TypeError: undefined is not an object (evaluating 'b.apply'). Exception occurred when checking element , check the 'remote' method.
I thought that my plugin is old and tried to use last version but I got the same error.
Can anyone tell me what I do wrong? How can I fix this bug?
Thanks in advance!
2
Answers
The following errors were made in my code
By fixing all these bugs I got right result.
You are missing a script file, including this script should solve the issue.