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:
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:
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: