note 87505 added to reserved.variables.get

From: Date: Mon, 08 Dec 2008 05:15:55 +0000
Subject: note 87505 added to reserved.variables.get
Groups: php.notes 
Request: Send a blank email to php-notes+get-147900@lists.php.net to get a copy of this message
Note: It is possible that you may have a set of input elements with the same name, like a multiple-select box or some checkboxes, as shown in code below. <?php if(isset($_GET["name"])){ var_dump($_GET); } ?> <html> <body> <form name="test_form" method="get"> Name:<br/> <input type="text" name="name"/><br/> Multiple Selection:<br/> <select name="select" multiple="true"> <option value="s1">s1</option> <option value="s2">s2</option> <option value="s3">s3</option> </select><br/> Checkboxes:<br/> <input type="checkbox" name="box" value="b1"/>Box 1<br/> <input type="checkbox" name="box" value="b2"/>Box 2<br/> <input type="checkbox" name="box" value="b3"/>Box 3<br/> <input type="submit" value="Submit"/> </form> </body> </html> For example, if I have selected "s1", "s2" and "s3" in the selection box and checked all the checkboxes, then I press submit button. The "Get" method gives me a query string like this: name=filledname&select=s1&select=s2&select=s3&box=b1&box=b2&box=b3 And what the "var_dump" function gives me is: array(3) { ["name"]=> string(10) "filledname" ["select"]=> string(2) "s3" ["box"]=> string(2) "b3" } Can you see? The reciever won't know that I have selected all data of the selection box and checkboxes. I will demonstrate some processes from the situation: 1. My $_GET["select"] is "s1", because the first key-value pair says that "select=s1". 2. My $_GET["select"] is changed to "s2", because another key-value pair says that "select=s2". 3. My $_GET["select"] is changed to "s3", because the last key-value pair says that "select=s3". So my $_GET["select"] is finally "s3" as shown in the "var_dump" function's output. And so do $_GET["box"]. I have found that the situation is also happened with $_POST. Now my solution is using javascript help mixing the values ("s1", "s2", "s3") in one hidden input element ("s1:s2:s3"), then send the string to receiver which will process it (split it and get the values). ---- Server IP: 69.147.83.197 Probable Submitter: 202.12.73.18 ---- Manual Page -- http://www.php.net/manual/en/reserved.variables.get.php Edit -- https://master.php.net/note/edit/87505 Del: integrated -- https://master.php.net/note/delete/87505/integrated Del: useless -- https://master.php.net/note/delete/87505/useless Del: bad code -- https://master.php.net/note/delete/87505/bad+code Del: spam -- https://master.php.net/note/delete/87505/spam Del: non-english -- https://master.php.net/note/delete/87505/non-english Del: in docs -- https://master.php.net/note/delete/87505/in+docs Del: other reasons-- https://master.php.net/note/delete/87505 Reject -- https://master.php.net/note/reject/87505 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#147900) next »