RE: Why is PHP unable to access my select list values?

From: Date: Thu, 04 Jul 2002 23:30:40 +0000
Subject: RE: Why is PHP unable to access my select list values?
Groups: php.general 
Request: Send a blank email to php-general+get-105513@lists.php.net to get a copy of this message
Gurus, I've finally figured out why the "managers[]" array wasn't being passed in the form's query string: like every form select list, I had to first select the options in the end-user created "managers[]" select list for them to be appear in the form's query string and therefore be accessible by PHP. The solution was to write a JavaScript function (called "selectOptions") that would select the options in the "managers[]" select list prior to the form's submission. See the modified HTML/JavaScript code below for an example (the "return false;" statement in the form's onSubmit attribute is there only to verify that the JavaScript "selectOptions" function works). ********* HTML/JavaScript code starts ********** <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>UPLOADS</title> <script language="javascript" type="text/javascript"> <!-- begin hide function onOptions(formName,toFieldName,fromFieldName){ var deptIndex = document[formName][fromFieldName].selectedIndex; if (deptIndex>0){ selectedArea = document[formName][fromFieldName]; } for (j=1;j<selectedArea.length;j++){ var noError = true; if (selectedArea.options[j].selected){ selectedText = selectedArea.options[j].text; selectedValue = selectedArea.options[j].value; for (i=1;i<document[formName][toFieldName].length;i++){ if (document[formName][toFieldName].options[i].value == selectedValue){ //duplication alert("Duplication: " + selectedText); noError = false; } } if (noError){ var len = document[formName][toFieldName].length; document[formName][toFieldName].options[len] = new Option(selectedText, selectedValue); } } } } function offOptions(formName,fieldName){ for (i=1;i<document[formName][fieldName].length; i++){ if (document[formName][fieldName].options[i].selected){ document[formName][fieldName].options[i] = null; i--; } } } var fieldNames = new Array(); function selectOptions(formName,fieldNames){ for (k=0;k<fieldNames.length;k++){ document[formName][fieldNames[0]].options[0].selected = false; for (i=1;i<document[formName][fieldNames[k]].length; i++){ if (document[formName][fieldNames[k]].options[i].value){ document[formName][fieldNames[k]].options[i].selected = true; } } } } // end hide--> </script> </head> <body> <table width="530" cellpadding="0" cellspacing="0" border="0"> <form name="formName" enctype="multipart/form-data" action="<?php echo $PHP_SELF; ?>" method="post" onsubmit="selectOptions('formName',['managers[]']); return false;"> <input type="hidden" name="MAX_FILE_SIZE" value="102400"> <tr> <td width="530" height="25" valign="top" colspan="2"><font class="required">*</font> <b>File:</b><br><input type="file" name="file" value="" size="68"></td> </tr> <tr> <td width="530" valign="top">Description:<br><textarea name="file_description" cols="79" rows="5">An internal file for authorized administrators only.</textarea></td> </tr> <tr> <td width="530" valign="top"> <table width="530" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="530" valign="top" colspan="3">choose managers</td> </tr> <tr> <td width="530" valign="top" colspan="3"> <select name="list_managers" size="5" multiple> <option value="">----------------------------------</option> <option value="1">test 1</option> <option value="2">test 2</option> <option value="3">test 3</option> </select> <a href="javascript:onOptions('formName','managers[]','list_managers');">ADD</a > | <a > href="javascript:offOptions('formName','managers[]');">REMOVE</a> <select name="managers[]" size="5" multiple> <option value="">----------------------------------</option> </select> </td> </tr> <tr> <td width="530" valign="top" colspan="3">Hold down CTRL key to select mutiple members</td> </tr> </table> </td> </tr> <tr> <td height="30" valign="top" colspan="2">&nbsp;</td> </tr> <tr> <td valign="top" colspan="2"> <input type="submit" name="submit" value="UPLOAD FILE"> &nbsp;&nbsp;&nbsp; <input type="reset" name="reset" value="RESET"> &nbsp;<br> <font class="required">*</font> <b>x:</b> = required form field. </td> </tr> <tr> <td height="30" valign="top" colspan="2">&nbsp;</td> </tr> </form> </table> </body> </html> ********* HTML/JavaScript code stops ********** O C:\DOS \-> C:\DOS\RUN /\ RUN\DOS\RUN -----Original Message----- From: Reginald Alex Mullin [mailto:ram@iamhewhois.org] Sent: Tuesday, July 02, 2002 7:34 PM To: 'php-general@lists.php.net' Subject: Why is PHP unable to access my select list values? Gurus, I've created the following file (see HTML/JavaScript code below) which allows end-users to dynamically (on the client-side) move items from one form select list (called "list_managers" to another (called simply "managers[]"). When, however, I attempt to access the end-user created "managers[]" form select list with PHP, I'm unable to do so! My testing (using the empty and isset functions) revealed that the "managers[]" array shows up as being empty, even though items were added to it from the "list_managers" select list prior to the form's submission. Has anyone encountered this problem before? What am I doing wrong here? Are there any suitable workarounds? P.S. Thank you, in advance, for all of your help and cooperation. O C:\DOS \-> C:\DOS\RUN /\ RUN\DOS\RUN

« previous php.general (#105513) next »