octane
I have issues, OK!
OK, some of the more seasoned php developers here might already know this, but this is something I figured out for myself some time ago .. being self taught, it's always a voyage of discovery!..
I hated creating forms. Each field and element would need to be passed to the next page / function and you'd have to keep track of all of those pesky form element names which have to be listed as globals inside every function that wishes to use them.
Worse still, if you're planning on moving them into session variables .. agghh!
There's a dead-easy way to manage all of those form elements that bundles them all together inside one big variable: an associative array.
For the newbies, an associative array is an array whose array elements have proper names rather than a zero-based numbered key.
To create the associative array, you need to go back to your html form and do this:
<input class="input" type="text" name="payment_array[textfield_cardholder]" size="30">
This is a simple form field. By giving the 'name' attribute a variable name [note: you DO NOT precede the variable name with a dollar sign] and then an associative title, you're telling php to first create an array variable called: 'payment_array' and then instructing it to change the array element key name to 'textfield_cardholder'. Any subsequent form elements will simply be adding their data to the same array variable .. simple!
As you can see, the naming convention is extremely helpful and self-explanatory. You don't need to fumble around trying to remember the name of each form element, you only need to add one variable name to you globals list and to access each array variable element, all you do is:
echo "Hi, " . $payment_array[textfield_cardholder] . "! You're transaction was successful...";
...
It's ruthlessly efficient and allows you to concentrate on coding and forget about lost variable names, missing form elements and the incumbent madness that is form validation.
Hope that helps...
I hated creating forms. Each field and element would need to be passed to the next page / function and you'd have to keep track of all of those pesky form element names which have to be listed as globals inside every function that wishes to use them.
Worse still, if you're planning on moving them into session variables .. agghh!
There's a dead-easy way to manage all of those form elements that bundles them all together inside one big variable: an associative array.
For the newbies, an associative array is an array whose array elements have proper names rather than a zero-based numbered key.
To create the associative array, you need to go back to your html form and do this:
<input class="input" type="text" name="payment_array[textfield_cardholder]" size="30">
This is a simple form field. By giving the 'name' attribute a variable name [note: you DO NOT precede the variable name with a dollar sign] and then an associative title, you're telling php to first create an array variable called: 'payment_array' and then instructing it to change the array element key name to 'textfield_cardholder'. Any subsequent form elements will simply be adding their data to the same array variable .. simple!
As you can see, the naming convention is extremely helpful and self-explanatory. You don't need to fumble around trying to remember the name of each form element, you only need to add one variable name to you globals list and to access each array variable element, all you do is:
echo "Hi, " . $payment_array[textfield_cardholder] . "! You're transaction was successful...";
...
It's ruthlessly efficient and allows you to concentrate on coding and forget about lost variable names, missing form elements and the incumbent madness that is form validation.
Hope that helps...