0

suppose I try to fetch previous $ variable (register_detail.php) to $_POST (register_submit.php)

example:

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>

to new 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'];

as we can see, can I fetch $ variable to $_POST?

4

2 回答 2

3

Put the values in hidden inputs. They can be anywhere in the form.

<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>
于 2013-05-18T04:06:42.173 回答
0

You can use hidden variables for your purpose .. you need not be concerned about table structure for that .. as they are not going to be displayed on UI you can put them whereever you want within

<form>
<table>
</table>
<input type='hidden' name='whatever' value="<?php echo $var;?>" />
</form>

you can have as many hidden variables in form as you want

于 2013-05-18T04:17:40.680 回答