开发者

validate form with database before moving on to the next page

开发者 https://www.devze.com 2022-12-23 15:07 出处:网络
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,

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号