note 35882 added to language.variables.external

From: Date: Thu, 18 Sep 2003 01:40:03 +0000
Subject: note 35882 added to language.variables.external
Groups: php.notes 
Request: Send a blank email to php-notes+get-56667@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/language.variables.external.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35882 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35882&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35882&report=yes

« previous php.notes (#56667) next »