PHP - Storing PHP Variables in Forms


A hidden field is a special type of input element that can store and send a string value, just like a regular text input control.

A hidden field is not displayed on the page although its value can be seen by viewing the page source.

Its value cannot be changed by the users when they're filling out the form.

By using hidden fields, you can store data between one browser request and the next:

<input type="hidden" name="selectedWidget" value="<?php echo $selectedWidget ?> " />

Do not use hidden fields to transmit sensitive or critical information such as user IDs or order numbers.


<form action="registration_multistep.php" method="post">
  <div style="width: 30em;">
    <input type="hidden" name="step" value="1" />
    <input type="hidden" name="gender" value="<?php setValue(" gender" ) ?>" />
    <input type="hidden" name="favoriteWidget" value="<?php setValue(" favoriteWidget" ) ?>" />
    <input type="hidden" name="newsletter" value="<?php setValue(" newsletter" ) ?>" />
    <input type="hidden" name="comments" value="<?php setValue(" comments" ) ?>" />

    <label for="firstName">First name</label>
    <input type="text" name="firstName" id="firstName" value="<?php setValue(" firstName" ) ?>" />
    <label for="lastName">Last name</label>
          <input type="text" name="lastName" id="lastName" value=" <?php setValue (" lastName" ) ?>" />
          <div style="clear: both;">
            <input type="submit" name="submitButton" id="nextButton" value= " Next &gt;" />

Related Topic