Miscellaneous

  Home arrow Miscellaneous arrow Page 2 - 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 - Using the function


    (Page 2 of 4 )

    How to use the function:

    1. The basic use couldn't be more simple. Somewhere in your second form, (best near the top before other fields), just add this code:

    <?php echo field_forwarder();?>

    You'll get hidden fields printed out for every form element that was passed. if you have form elements that are ARRAYS, it works for those too.

    2. Use other sources for field_forwarder()

    What the function is looking at is the $_POST collection, which is an array. You can also use other arrays in place of this. Suppose you had an included file with the following array declared:

    <?php
    $info
    ['residence']['recent'] = "123 Main Street.";
    $info['residence']['previous'] = "1044 S. Fedora Drive";
    $info['interests'][1] = 'hockey';
    $info['interests'][2] = 'figure skating';
    $info['name'] = 'Samuel "Sambo" Fullman';
    $info['company'] = 'Compass Point Media';
    ?>

    To get this into fields, we'd just declare the following after the array has been declared:

    &lt;?php echo field_forwarder('info');?&gt;

    And instead of the form collection, it'll output the $info array as follows:

    &lt;input type="hidden" name="info[residence][recent]" value="123 Main Street."&gt;
    &lt;input type="hidden" name="info[residence][previous]" value="1044 S. Fedora Drive"&gt;
    &lt;input type="hidden" name="info[interests][1]" value="hockey"&gt;
    &lt;input type="hidden" name="info[interests][2]" value="figure skating"&gt;
    &lt;input type="hidden" name="info[name]" value="Samuel &amp;quot;Sambo&amp;quot; Fullman"&gt;
    &lt;input type="hidden" name="info[company]" value="Compass Point"&gt;

    Two things to note here: 1) When you declare arrays in HTML form elements, you DON'T put quotes around string indexes, 2) the quotes for "Sambo" were replaced with &quot;, otherwise the browser wouldn't know where the value ends.

    My function handles arrays quite handily. In fact there is no real limit on the number of keys (indexes) that can be used. If you're actually strange enough to have an array element called:

    <?php
    $animals
    ['cordates']['vertebrates']['mammals']['quadripeds']['canines']['Great Danes']['my pet'] = "Rover"
    ?>

    it's not a problem.

    3. Output PHP code instead of hidden fields

    This function can also output the code for a PHP array instead of hidden fields. Just add the following before you declare the function:

    <?php
    $FFoutputType 
    ='print'#must be lowercase print
    echo field_forwarder();
    ?>

    This is great if you want to store PHP-style arrays in a database to be evaluated later on.

    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 7 - Follow our Sitemap