简体   繁体   English

在进入下一页之前,使用数据库验证表单

[英]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. 一个用户友好的解决方案是使用javascript来做到这一点,因此不必在页面上重新加载错误。 Take a look at the jQuery validate plugin . 看一下jQuery validate插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM