note 35882 deleted from language.variables.external by didou
| From: | didou@php.net | Date: | Wed, 21 Jan 2004 09:30:52 +0000 |
| Subject: | note 35882 deleted from language.variables.external by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63937@lists.php.net to get a copy of this message | ||
Note Submitter: dbradfor@nwlink.com
----
PHP will not translate a POSTed select-multiple field on an HTML form into an array in the
corresponding $_POST variable unless the form field name attribute includes array-like
square-bracket syntax. (e.g. "name=beer[]"). Unfortunately this can cause infuriating
problems in pre-existing JavaScript code which is not designed for bracketized field names.
Here is a JavaScript hack to help get over the frustration of that questionable PHP design decision:
Declare a JavaScript function similar to the following hack, and execute it using the form's
onSubmit event handler:
<SCRIPT LANGUAGE="JavaScript">
<!--
function phpPrepareForm() {
for ( i=0; i < document.forms[0].length; i++ ) {
if (document.forms[0].elements[i].type=="select-multiple") {
namebrackets=document.forms[0].elements[i].name + "[]";
document.forms[0].elements[i].name=namebrackets;
}
}
}
//-->
</SCRIPT>
I don't know how cross-browser compatible it is but it seems to work for me.