Fw: [PHP] Multi-select inputs and naming

From: Date: Mon, 10 Mar 2003 18:43:16 +0000
Subject: Fw: [PHP] Multi-select inputs and naming
Groups: php.general 
Request: Send a blank email to php-general+get-138995@lists.php.net to get a copy of this message
----- Original Message ----- From: "Dan Phiffer" <dan@phiffer.com> To: <php-general@lists.php.net> Sent: Monday, March 10, 2003 11:24 AM Subject: [PHP] Multi-select inputs and naming > Hello, > > Am I correct in my understanding that for a multi-select input, PHP requires > that the name attribute end with square brackets (i.e. <select > name="my_select[] multiple>") in order for the submission be handled > properly? > > I know this is somewhat nit-picky, but this seems to unnecessarily expose > the underlying technology such that scanning the HTML source reveals that a > PHP script will ultimately parse the submission. > > I'm hoping there's some alternative technique I've missed... > > -Dan Yes. The values must be passed as an array. In order to do that the select tag requires the [] braces. The proper syntax is: <select name="my_select[]" multiple> <option>One</option> <option>Two</option> <option>Three</option> </select> <? // To read the selected items... for($i=0; $i<count($_POST['my_select']); $i++) { echo $_POST['my_select'][$i]."<br>"; } ?> Hope that helps. - Kevin

« previous php.general (#138995) next »