How to do Javascript for the HTML/PHP Array (See Below)
| From: | Scott Fletcher | Date: | Wed, 17 Sep 2003 13:35:14 +0000 |
| Subject: | How to do Javascript for the HTML/PHP Array (See Below) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-162864@lists.php.net to get a copy of this message | ||
Hi Fellas!
Here's the clipping of an article about putting HTML variables into a
PHP Array upon submission. Right now, I'm having trouble getting Javascript
to do the error checking of each of the HTML variable if it's variable name
is treated as an array. Anyone know of a workaround to it where Javascript
can detect and work with the HTML Array-like variable name???
--snip--
3. How do I create arrays in a HTML <form>?
To get your <form> result sent as an array to your PHP script you name the
<input>, <select> or <textarea> elements like this: <input
name="MyArray[]">
<input name="MyArray[]">
<input name="MyArray[]">
<input name="MyArray[]">
Notice the square brackets after the variable name, that's what makes it an
array. You can group the elements into different arrays by assigning the
same name to different elements: <input name="MyArray[]">
<input name="MyArray[]">
<input name="MyOtherArray[]">
<input name="MyOtherArray[]">
This produces two arrays, MyArray and MyOtherArray, that gets sent to the
PHP script. It's also possible to assign specific keys to your arrays:
<input name="AnotherArray[]">
<input name="AnotherArray[]">
<input name="AnotherArray[email]">
<input name="AnotherArray[phone]">
The AnotherArray array will now contain the keys 0, 1, email and phone.
Note: Specifying an arrays key is optional in HTML. If you do not specify
the keys, the array gets filled in the order the elements appear in the
form. Our first example will contain keys 0, 1, 2 and 3.
See also Array Functions and Variables from outside PHP.
--snip--