note 74775 added to language.variables.external

From: Date: Fri, 27 Apr 2007 00:05:27 +0000
Subject: note 74775 added to language.variables.external
Groups: php.notes 
Request: Send a blank email to php-notes+get-125904@lists.php.net to get a copy of this message
For anyone else having trouble figuring out how to access values in a SELECT element from a POST or GET form, you can't set the "id" attribute to the same thing as your "name" attribute. i.e. don't do this: <?php //Not so good <select multiple="multiple" id="selectElem" name="selectElem[]"> <option value="ham">Ham</option> <option value="cheese">Cheese</option> <option value="hamcheese">Ham and Cheese</option> </select> ?> If you do the above, the variable $_POST['selectElem'] will not be set. Instead, either change the id or name attribute so that they are dissimilar. i.e. do this: <?php //So good (notice the new "id" value) <select multiple="multiple" id="selectElemId" name="selectElem[]"> <option value="ham">Ham</option> <option value="cheese">Cheese</option> <option value="hamcheese">Ham and Cheese</option> </select> ?> Then you can access the value(s) of the SELECT element through the array $_POST['selectElem'][] or $_GET['selectElem'][]. It took me quite some time to figure out the problem. ---- Server IP: 64.71.164.2 Probable Submitter: 64.136.26.225 (proxied: 67.150.209.192, 64.136.26.19) ---- Manual Page -- http://www.php.net/manual/en/language.variables.external.php Edit -- https://master.php.net/note/edit/74775 Del: integrated -- https://master.php.net/note/delete/74775/integrated Del: useless -- https://master.php.net/note/delete/74775/useless Del: bad code -- https://master.php.net/note/delete/74775/bad+code Del: spam -- https://master.php.net/note/delete/74775/spam Del: non-english -- https://master.php.net/note/delete/74775/non-english Del: in docs -- https://master.php.net/note/delete/74775/in+docs Del: other reasons-- https://master.php.net/note/delete/74775 Reject -- https://master.php.net/note/reject/74775 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125904) next »