如何提交两个php表单到一个位置


How to submit two php forms to one location

我有两个php表单,都用于注册手段(输入名称,用户名,密码等)。我的第一个注册表单(reg1.php)包含我上面提到的基本输入,然后我有第二个注册表单(reg2.php),其中包括复选框,表单将在最终注册之前向用户询问其他问题。

我遇到的问题是,当我在第一个注册表单中输入数据,然后进入下一个注册页面并填写并单击注册时,我在服务器上的输出只获得我在第二个注册页面中输入的信息,而不是第一个。

如何让两个注册页面的输入数据一起显示?有人告诉我POSTBACK可以帮助我解决这个问题,但我不太熟悉如何使用它。

第一个php页面:

<body>
<?php include("menu.php"); ?>
<div id="main">
<h2>Sign Up</h2>
<table style="width:300px">
<form name="Rego" method="post" action="rego2.php">
<tr>
<td><label>Name:</label></td>
<td><input type="text" name="fname"/></td>
</tr>
<tr>
<td><label>Username:</label></td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td><label>Password:</label></td>
<td><input type="password" name="password" id="pass" /></td>
</tr>
<tr>
<td><label>Confirm Password:</label></td>
<td><input type="password" name="conpassword" id="conpass"/></td>
</tr>
<tr>
<td><p><input class="button" type="submit" value="Next Page">
<input class="button" type="reset" value="Reset"></p></td>
</tr>
</form>
</table>
</div>
</body>

第二个php页面

<body>
<?php include("menu.php"); ?>
<div id="main">
<h2>Sign Up</h2>
<table>
<form name="Rego" method="post" action="http://myserver...">
<tr>
<td>
<input type="checkbox" name="checkbox" value="Agree to T&C">I agree to the <a href="tnc.php">Terms and Conditions</a><br> 
<input type="checkbox" name="checkbox" value="No Criminal Records">I have no criminal associations<br>
</td>
</tr>
<tr>
<td><p><input class="button" type="submit" value="Sign Up">
<input class="button" type="reset" value="Reset"></p></td>
</tr>
</form>
</table>
</div>
</body>

当第一个表单被提交时,要么将数据存储在$_SESSION变量中,然后在处理第二个表单时检索它,要么将其写入第二个表单上隐藏的<input>元素中,然后从$_GET$_POST数组中检索它

在第二个输入表单中,您从value中取出第一个输入,并将其隐藏。

和第二个输入形式你应该

<body>
<?php include("menu.php"); ?>
<div id="main">
<h2>Sign Up</h2>
<table>
<form name="Rego" method="post" action="http://myserver...">
<input type="hidden" name="fname" value="<?php echo  $_POST['fname'];?> " />
<input type="hidden" name="username" value="<?php echo  $_POST['username'];?> " />
<input type="hidden" name="passowrd" value="<?php echo  $_POST['password'];?> " />
<input type="hidden" name="conpassowrd" value="<?php echo  $_POST['conpassword'];?> " />
<tr>
<td>
<input type="checkbox" name="checkbox" value="Agree to T&C">I agree to the <a href="tnc.php">Terms and Conditions</a><br> 
<input type="checkbox" name="checkbox" value="No Criminal Records">I have no criminal associations<br>
</td>
</tr>
<tr>
<td><p><input class="button" type="submit" value="Sign Up">
<input class="button" type="reset" value="Reset"></p></td>
</tr>
</form>
</table>
</div>
</body>

我希望它对你有用。

在第二页中,您可以从第1页获取帖子数据,并将其设置在隐藏字段中,如fname:

<input type="hidden" name="fname" id="fname" value="<?php echo $_POST['fname'] ?>">

当您从第二个页面提交时,您可以在目标页面中捕获这些数据,例如

$_POST['fname']