PHP HTML HiddenField to Pass data in multiple pages

From CoderLearner
Jump to: navigation, search

PHP uses Hidden Fields for multiple page

User hidden field for passing form data to multiple pages. See example for more detail.

Step 1 (1.php)

  • Ask user name
<html>
   <head>
      <title>Full Name</title>
   </head>
   <body>
      <form action="2.php" method="post">
         Name: <input type="text" name="fullname" size="20" maxlength="20"/>
         <input type="submit" name="submit" value="Step 1"/>
      </form>
   </body>
</html>

Step 2 (2.php)

<html>
   <head>
      <title>Email</title>
   </head>
   <body>
      <form action="3.php" method="post">
         Email: <input type="text" name="email" size="20" maxlength="20"/>
         <input type="submit" name="submit" value="Step 2"/>
         <input type="hidden" name="fullname" value="<?= $_POST['fullname'] ?>">
      </form>
   </body>
</html>

Step 3 (3.php)

<?php

echo "Name: {$_POST['fullname']} <br/>";
echo "Email: {$_POST['email']} <br/>";
?>

Try It