views:

46

answers:

2

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?

A: 

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.

oli
+1  A: 

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();
    }
}
?>
Bowen
Thanks, this has been quite helpful.
Tunji Gbadamosi