Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP多页表单验证_Php_Html_Forms - Fatal编程技术网

PHP多页表单验证

PHP多页表单验证,php,html,forms,Php,Html,Forms,这是一个很难回答的问题,所以我会尽我最大的努力。我是一个书呆子,对php知之甚少,所以请善待我:D <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form>

这是一个很难回答的问题,所以我会尽我最大的努力。我是一个书呆子,对php知之甚少,所以请善待我:D

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
我想在作为表单处理程序的页面上验证表单,例如,我的第一个表单页面(取自W3S):

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
……等等

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
问题是,我一进入这个页面,它就直接从上一个页面验证表单,并在页面上显示空字段的错误。
有什么方法可以避免这种情况吗?因此我需要一种新的方法。

我理解您的问题,您需要首先检查在验证代码段中提交的表单

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
在第二种形式中插入新的隐藏字段,当您验证
newBalance
字段时,检查是否设置了
操作
<代码>操作字段仅在提交form2时设置

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
下面是可以帮助您的代码

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
welcome.php

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
// Form2
<form method="post">
    <input type ="text" name="newBalance"><span class="error">*<?php echo    $balanceErr;?></span>
    <input type ="hidden" name="action" value="true" />
</form>

上面的代码可以帮助您。

将值存储到数据库,然后在welcome.php上从DB回显它们吗?如果验证结果正确,我将它们存储在数据库中,我不想在错误检查之后再写入数据库。请在第二个表单中添加另一个带有名称的提交按钮。Than-首先检查按钮是否被单击,然后检查您的状况
(空($\u POST[“newBalance”])
是的,我喜欢这个声音。我已经有第二个按钮了。那么这是正确的吗。。。。在验证循环中有if(isset($\u POST['Submit\u button\u 2']){execute validation}??如果表单操作提交给自身,则无需设置表单操作:)
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>