PHP Form Demo

Example

Name the following file as index.htm file.


       <!DOCTYPE html5>/* w ww  .  java 2s .c  o m*/
       <html> 
         <body> 
           <form action="index.php" method="post"> 
               <label for="firstName">First name</label> 
               <input type="text" name="firstName" id="firstName" value="" /> 

               <label for="lastName">Last name</label> 
               <input type="text" name="lastName" id="lastName" value="" /> 

               <label for="password1">Choose a password</label> 
               <input type="password" name="password1" id="password1" value="" /> 
               <label for="password2">Retype password</label> 
               <input type="password" name="password2" id="password2" value="" /> 

               <label for="genderMale">Are you male...</label> 
               <input type="radio" name="gender" id="genderMale" value="M" /> 
               <label for="genderFemale">...or female?</label> 
               <input type="radio" name="gender" id="genderFemale" value="F" /> 

               <label for="favoriteWidget">What's your favorite widget?</label> 
               <select name="favoriteWidget" id="favoriteWidget" size="1"> 
                 <option value="superWidget">The SuperWidget</option> 
                 <option value="megaWidget">The MegaWidget</option> 
                 <option value="wonderWidget">The WonderWidget</option> 
               </select> 

               <label for="newsletter">Do you want to receive our newsletter?</label> 
               <input type="checkbox" name="newsletter" id="newsletter" value="yes" /> 

               <label for="comments">Any comments?</label> 
               <textarea name="comments" id="comments" rows="4" cols="50"> </textarea> 
               <div style="clear: both;"> 
                 <input type="submit" name="submitButton" id="submitButton"  value="Send Details" /> 
                 <input type="reset" name="resetButton" id="resetButton" value="Reset Form" style="margin-right: 20px;" /> 
               </div> 
           </form> 
         </body> 
       </html> 

Next, save the following script as index.php in the same folder with index.html.


<!DOCTYPE html5> /* www .  j  a  v  a  2 s  .  c  om*/
<html> 
  <body> 
    <p>Thank you for registering. Here is the information you submitted:</p> 
    <dl> 
      <dt>First name</dt><dd><?php echo $_POST["firstName"]?></dd> 
      <dt>Last name</dt><dd><?php echo $_POST["lastName"]?></dd> 
      <dt>Password</dt><dd><?php echo $_POST["password1"]?></dd> 
      <dt>Retyped password</dt><dd><?php echo $_POST["password2"]?></dd> 
      <dt>Gender</dt><dd><?php echo $_POST["gender"]?></dd> 
      <dt>Favorite widget</dt><dd><?php echo $_POST["favoriteWidget"]?></dd> 
      <dt>Do you want to receive our newsletter?</dt><dd><?php echo $_POST["newsletter"]?></dd> 
      <dt>Comments</dt><dd><?php echo $_POST["comments"]?></dd> 
    </dl> 
  </body> 
</html> 




















Home »
  PHP Tutorial »
    Form »




PHP Form
Form Demo