Miscellaneous

  Home arrow Miscellaneous arrow Page 3 - 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 - Examining the Function


    (Page 3 of 4 )

    Usually I'd give a very detailed explanation of how a function works, but this one was very complex conceptually, and so I'll just hit some high points.

    First of all, this is a recursive function, which means that under certain conditions it calls itself. Recursive functions are a good way to get something done fast, and also a safe way as I believe functions are set up in their own separate memory space. The flip side of designing recursive functions is that you must be careful to declare globals as you need them. For example, if you a function called some_kind_of_loop() which declares variables, you must either declare them as global or pass them to the function the next layer down, or they won't be available at that level.

    Secondly, for those of you who may not know, the following two array elements are different:

    <?php
    $info
    ['interests'][01] = 'hockey';
    $info['interests']["01"] = 'figure skating';
    ?>

    Try echoing these both and you'll see what I mean. In the first case the 01 is taken as a number, and the second it's taken as a string (even though it's a numeric value and you can still add and operate on it math-wise). In my function, quotes are NOT added if the key (index) is purely numeric. This may cause a bug if you're using some value like 01, so you can get in and change that in the code, see lines 54-58 to change this.

    Finally, remember that when you put a value in a form, it may contain a double quote, and if you have magic runtime quotes turned on, values with a single quote will have a slash added. For example, this line of string,

    I didn't "do it," she said.

    will show like this:

    I didn\'t

    That's because single quotes will have a slash added on posting, and the double quote is interpreted as the end of the value.

    To correct this, my function takes the following string and filters it through two PHP functions:

    <?php
    $value 
    'I didn\'t "do it," she said';
    htmlentities(stripslashes($value));
    ?>

    This changes the string to:

    I didn't &amp;quot;do it,&amp;quot; she said

    Which will post correctly.

    More Miscellaneous Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Attention: Forum and Site Maintenance
    - 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

    Developer Shed Affiliates

     



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