validate form with database before moving on to the next page
I want to validate a form input with my database before allowing a user to go to the next page of a checkout process. So, if the data is corrrect => go to the next stage, else => stay at the current page, allowing the开发者_运维问答 user to ammend their input
How would I do this?
I'd recommend that you do server side validation if it is critical that the input is to be validated.
This is a bit of pseudo code, but I would do something like this.
<?php
if($_POST)
{
$error = FALSE;
// Do your validation here, if some fails, set some
// error messages and set $error = TRUE
if(!$error)
{
// There wasn't any errors carry onto next page
header('Location: /url/to/next/page.php');
exit();
}
}
?>
A user friendly solution is to use javascript to do that, so the page doesn't have to be reloaded with the errors. Take a look at the jQuery validate plugin.
精彩评论