I’m trying to recreate the Remember the Milk Signup form validation example (from JQuery Validate plugin wiki). Especifically for username remote validation. If you check the example, you’ll see two links at the bottom, one for client-side and the other for server-side code. The second one is not working (In all three browsers I’ve tried with).
So, please, does anyone have this server-side code, a link to it, or any compatible alternative that works with the client-side code provided?
P.D. I’m trying to follow stackoverflow rules with this question. If its not valid, please give me some advise.
NOTE: Got it working thanks to @Marc B answer, I didn’t know how to pass the data between the form and the checkusername.php, I do know.
What I was using at first (Not working):
JS rules:
(...)
$('form').find('.classNewUsernameField').each(function () {
$(this).rules('add', {
required: true,
remote: "checkusername.php",
minlength: minLengthField,
messages: {
required: "Required field!",
remote: "Taken!",
minlength: "Too short"
}
});
});
Server-side:
if (!mssql_connect("127.0.0.1", "user", "pass"))
exit ("->FAILED");
if (!mssql_select_db("db_rrhh"))
exit ("FAILED DB");
$query = "SELECT username_user FROM table_users WHERE username_user=".$_POST['username'];
$res = mysql_query($query);
if (mysql_num_rows($res) > 0) {
$output = true;
} else {
$output = false;
}
echo json_encode($output);
Here’s the server-side code (how to fetch: view demo page source, see that it’s fetching a .phps file, hit url manually, download file, load into notepad, cut& paste here)
pretty silly code overall.