用不同的 "GET "变量提交重定向到当前的url。

问题描述 投票:0回答:1

我在一个文件里有一个表格,叫做 SignUpForm.php当它被提交时,页面会被重定向到网址。http://localhost/MySite/Includes/SignUp.php?step=1,并在文件中 SignUp.php我有3个表格,每个表格只显示其对应的 ?step=x 值。在第一种形式中(以 ?step=1) 我有以下代码

if(isset($_GET['step']) === true && empty($_GET['step']) === false){
        if(isset($_POST['SignUpStep1Submit'])) {
                // some code here
                header('Location: SignUp.php?step=2');
        }

// forms displaying codes with the $_GET['step'] conditions

所以问题是,我想提交第一个表格,所以它重定向我到相同的 .php 文件,但执行了前面的代码后,却用了?step=2,而当我提交表单时,我最终得到的是 http://localhost/MySite/Includes/SignUp.php......步长变量没有设置,而在 //some code here 根本就没有被执行,它所做的只是把我重定向到了 SignUp.php 没有 ?step 值,给我留下一个空白页

php html forms get form-submit
1个回答
0
投票

为什么你不直接修改表单的操作来包含步骤变量,这样表单1的操作将是

<form name="form1" action="/signup.php?step=2" method="post"></form>

对于表格2来说,它将是

<form name="form2" action="/signup.php?step=3" method="post"></form>

要在提交表单之前检查表单值是否有效,您可以使用 patternrequired 属性,例如

<input name="firstname" pattern=".{3,}" required title="Your first name should be at least 3 characters long">

<input name="city" pattern=".{1,30}" required title="The country field shouldn't be more than 30 characters">

required 检查输入框是否已被填入。

pattern 使用regex模式来检查已经填写的值的类型...模式。这里有更多信息。https:/www.w3schools.comtagsatt_input_pattern.asp

© www.soinside.com 2019 - 2024. All rights reserved.