PHP and HTML interact a lot : PHP generate HTML, and HTML has informations that will be sent to PHP.
1. I'm trying to use an <input type="image"> tag, but the $foo.x and $foo.y variables aren't available. Where are they?
When submitting a form, it is possible to use an image instead of the standard submit button with a tag like:
<input type="image" src="image.gif" name="foo"> |
Because $foo.x and $foo.y are invalid variable names in PHP, they are automagically converted to $foo_x and $foo_y. That is, the periods are replaced with underscores.
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[]"> |
<input name="MyArray[]"> <input name="MyArray[]"> <input name="MyOtherArray[]"> <input name="MyOtherArray[]"> |
Note: You need not use indices with arrays in HTML, although you can specify number or associative indices, so you can exactly specify what indices will contain the information provided by that input element. If you do not specify indices, the array gets filled in the order the elements appear in the form.
For functions you can use to process these arrays once you get them into your scripts, please see the Arrays section.
The select multiple tag in an HTML construct allows users to select multiple items from a list. These items are then passed to the action handler for the form. The problem is that they are all passed with the same widget name. ie.
<select name="var" multiple> |
var=option1 var=option2 var=option3 |
<select name="var[]" multiple> |
Note that if you are using JavaScript the [] on the element name might cause you problems when you try to refer to the element by name. Use it's numerical form element id instead, or enclose the variable name in single quotes and use that as the index to the elements array, for example:
variable = documents.forms[0].elements['var[]']; |