I have a question regarding the php validation, I have this script
$(document).ready(function(){
// validate signup form on keyup and submit
var validator = $("#contactform").validate({
rules: {
email: {
email: true,
required: true,
remote: { url: "test.php", type: "post" }
}
},
messages: {
email: {
email: "Enter a valid email adress",
required: "This input is required",
remote: "Email adress is in use"
}
},
// set this class to error-labels to indicate valid fields
success: function(label) {
label.addClass("checked");
}
});
});
and the validation script from test.php is
define('__ROOT__', dirname(dirname(dirname(__FILE__))));
require_once (__ROOT__.'/config.php');
$email = mysql_real_escape_string($_POST['email']);
$SQL = $mysqli->query("SELECT * FROM users WHERE email='$email'");
If($SQL->num_rows == 0) {
echo 'true';
} else {
echo 'false';
}
How can I make the validation from the php file to be more complex like: I want to add a rule to check if the email is valid ( just in case someone don’t have javascript active ) but if I try something like this the validation script wont return me an error message if the email address is in the database
If(filter_var($email, FILTER_VALIDATE_EMAIL) == false) {
$SQL = $mysqli->query("SELECT * FROM users WHERE email='$email'");
If($SQL->num_rows == 0) {
echo 'true';
} else {
echo 'false';
}
}
There are some problems around the
remoteusage withjquery.validate. Check if you did the following:1) Make sure you are using jQuery version 1.6.1 and above only.
2) Use the “synchronous” option for remote execution (default being asynchronous) and set
asyncoption tofalse.Usage: