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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.