I'm developing a Web site for a school project. Though I mainly work with PHP, I thoght I should as well do some client-side validation. It took a very short search in Google to find the Validate JQuery plugin. And so far this is what I've got:
<form id="regform" class="well" method="post" action="Registering.php">
<label>Name: <input type="text" placeholder="Type your name" name="Name" class="required" /></label>
<label>Surname: <input type="text" placeholder="Type your surname" name="Surname" class="required" /></label>
<label>Username: <input type="text" placeholder="Type your username" name="Username" class="required" /></label>
<label>Password: <input type="password" placeholder="Type your password" name="Password" class="required" /></label>
<label>Repeat Password: <input type="password" placeholder="Confirm Password" name="Password-confirm" class="required" /></label>
<label>E-Mail: <input type="Email" placeholder="Type your Email" name="Email" class="required email" /></label>
<label>Birthday: <input type="Date" name="Birthday" /></label>
<label>Gender:</label>
<label>Male <input type="radio" name="Gender" value="0" checked> Female <input type="radio" name="Gender" value="1"></label>
<label>Photo: <input type="url" placeholder="Paste an image link" name="PhotoLink" class="url" /></label>
<label><input type="submit" class="btn btn-primary" name="Submit" value="Register in YouTune" /></label>
</form>
This is the form, pretty much a standard registration one. Nothing to add here. And then I have this small Javascript:
$(document).ready(function(){
$("#regform").validate({
rules: {
Username: {
remote: { url: "/check_username.php", async: false }
}
},
messages: {
Username: { remote: "Username already on use. Pick a different one." }
}
});
});
Both scripts of the lastest JQuery library and the version 1.10 of the Validate Plugin were added on the head of the document.
Well, to make it short, the validation stuff runs smooth, except that the remote rule is not working. It is as if it wasn't there at all, no error message whether I submit with an already used Username or not. The php file that the Javascript is calling has the following script:
<?php error_reporting(E_ALL);
require_once("../Clases/User.php");
header('Content-type: application/json');
$vUser = new User();
$vResult = $vUser->GetUserByUsername($_REQUEST["Username"]);
if ($vResult) {
echo false;
} else { echo true; }
?>
The GetUserByUsername method goes to a DataBase and searches for a User with the given parameter, then returns true if there was a match up, false if there wasn't. I've tested it without the remote call from the Javascript and it works fine
So, does anyone know why is this happening?
Thank you beforehand for taking the time read and trying to help me with this small issue.
EDIT: Solved. I just had to fix the source for the remote call. Can't believe I missed that. Anyway, thank you very much for the help.