When a user fills a login form with an username and a password I use php to do a server-side validation of the data inputted by comparing it with the one in the "users" table in the SQL database. I'd like to notify the user if the password is incorrect without redirecting him - using a javascript dialog, for instance. Is that possible? The only way I found to notify the user was:
if ($password_given != $password_from_db) {
echo "Wrong password."; // Dull non-html notification issued by the server
};
or
if ($password_given != $password_from_db) {
header('Location: index.php?page=wrongpassword'); //Need redirection
};
Is there anyway to this differently?
A javascript to get the inputted data, send it to the server to be processed is an idea, but how could I return a result for the javascript to use?
JQuery
$.post("test.php", $("#testform").serialize())
.done(function(data) {
if( data=='validated')
window.location.href = "successpage.php";
else
alert ('password dont match!');
});
php
if ($password_given != $password_from_db)
echo "notvalidated.";
else
echo echo "validated.";