假设我尝试将以前的$ variable(register_detail.php)提取到$ _POST(register_submit.php)
示例:
register_detail.php
<form action="register_submit.php" method='POST'>
<table>
<tr><td>Name:</td> <td><?php print ($name); ?></td></tr>
<tr><td>I/C:</td> <td><?php print ($ic); ?></td></tr>
<tr><td>e-mail:</td> <td><?php print ($email); ?></td></tr>
<tr><td>Address:</td> <td><?php print ($address); ?></td></tr>
<tr><td>Date of Birth:</td> <td><?php print ($dob); ?></td></tr>
<tr><td>Contact:</td> <td><?php print ($contact); ?></td></tr>
</table>
<?php $password; ?> -- this was not meant to be displayed --
<input type='submit' name='submit' value='Confirm'><input type='button' value='Cancel' onclick='history.go(-1);return false;'/>
</form>
到新的php(register_submit.php)
if (isset($_POST['name']) && isset($_POST['ic']) && isset($_POST['email']) && isset($_POST['address']) && isset($_POST['dob']) && isset($_POST['contact']) && isset($_POST['password']))
$name = $_POST['name'];
$ic = $_POST['ic'];
$email = $_POST['email'];
$address = $_POST['address'];
$dob = $_POST['dob'];
$contact = $_POST['contact'];
$password = $_POST['password'];
我们可以看到,我可以将$变量提取到$ _POST吗?
答案 0 :(得分:3)
将值放入隐藏的输入中。它们可以是表格中的任何地方。
<form action="register_submit.php" method='POST'>
<table>
<tr><td>Name:</td> <td><?php print ($name); ?></td></tr>
<tr><td>I/C:</td> <td><?php print ($ic); ?></td></tr>
<tr><td>e-mail:</td> <td><?php print ($email); ?></td></tr>
<tr><td>Address:</td> <td><?php print ($address); ?></td></tr>
<tr><td>Date of Birth:</td> <td><?php print ($dob); ?></td></tr>
<tr><td>Contact:</td> <td><?php print ($contact); ?></td></tr>
</table>
<input type="hidden" name="name" value="<?php echo $name; ?>">
<input type="hidden" name="password" value="<?php echo $password; ?>">
<input type="hidden" name="ic" value="<?php echo $ic; ?>">
... repeat for all the fields
<input type='submit' name='submit' value='Confirm'><input type='button' value='Cancel' onclick='history.go(-1);return false;'/>
</form>
答案 1 :(得分:0)
您可以将隐藏变量用于您的目的.. 你不必担心表的结构..因为它们不会在UI上显示,你可以把它们放在你想要的内容
<form>
<table>
</table>
<input type='hidden' name='whatever' value="<?php echo $var;?>" />
</form>
您可以根据需要在表单中包含任意数量的隐藏变量