This is a much condensed version of the original post.
Usually, processing form data means getting either POST or GET data from a form, and trying to figure out, in code, what you have, and then do something with it. This can be easy or complicated, depending on how much is being passed in. Email address only? Easy. Checkboxes, optional fields, and so on, all together? Pain. Often, a lot of form processing is done with stacks of “if” statements. This sucks. Here is a better way:
From now on, I want you to name all of your “real” form elements (ones that have data that could change, so not buttons) using the name you would have given then, plus an array name, that they will all share.
So,
<input type="text" name="username" id="username" />
becomes
<input type="text" name="formdata[username]" id="username" />
Why? Instead of having one array ($_POST), you’ll now have two ($_POST and ‘formdata’, within $_POST). Your buttons and other “static” form elements will still live in $_POST, but everything containing data that needs handling will be in the ‘formdata’ array, which you can access as $_POST[formdata].
Read full story