Miscellaneous

  Home arrow Miscellaneous arrow Multi-page Forms with PHP
MISCELLANEOUS

Multi-page Forms with PHP
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2002-11-12

    Table of Contents:
  • Multi-page Forms with PHP
  • Using the function
  • Examining the Function
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Multi-page Forms with PHP


    (Page 1 of 4 )

    This article will touch on two skills in the interface between PHP and HTML forms, specifically in working with hidden fields, and as a bonus, in passing arrays in an HTML form.

    By : Sam Fullman

    This article will touch on two skills in the interface between PHP and HTML forms, specifically in working with hidden fields, and as a bonus, in passing arrays in an HTML form.

    If you've been on the web at all, you've gone through multipart forms, where you fill out, let's say, section one, click submit, and fill in section two, etc.. This makes sense from dividing the forms into chunks, controlling the amount of information received, and also for verfication. If we want the user to set up an account with us, we might want to make sure that the username and password they select are unique before we have them fill out much else.

    At some point in your coding career, you're going to need to use hidden fields to hold values from a previous form. For example, if Form 1 had an input field as follows:

    <input type='text' name='username'>

    And you have globals turned on, Form 2 should carry this hidden field:

    <input type='hidden' name='username' value='<?php echo $username;?>'>

    This will "forward" the value of the text field to the hidden field on the second form. If you have globals turned OFF, you'll need to rewrite the second field slightly:

    <input type='hidden' name='username' value='<?php echo $_POST['username'];?>'>

    The concept is pretty simple; this way when the user submits Form 2, the values on form 1 go along with it. However, if you've got 5 forms with 15 questions each, form 2 will have 15 hidden fields, form 3 will have 30, form four will have 45, etc. That's a lot of hand coding, AND you'll have to change (5-n) fields if you change 1 question on Form n.

    I finally came to the point where I'd had enough, and this function I'm providing was the answer. The name of the function is field_forwarder(), and it's going to be a good friend on some of the complex projects I'm about to head up. In a nutshell, it takes all of the fields in a form collection, and outputs HTML hidden fields. Please click here for the code.

    More Miscellaneous Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap