Miscellaneous
  Home arrow Miscellaneous arrow Page 2 - Multi-page Forms with PHP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

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

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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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


       · Hi there,I checked this tutorial. what about passing variables to another HTML...
       · Please excuse me if I missed something.The tutorial says which code goes in page...
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT