multiple select form elements question

From: Date: Thu, 09 May 2002 14:55:21 +0000
Subject: multiple select form elements question
Groups: php.general 
Request: Send a blank email to php-general+get-96816@lists.php.net to get a copy of this message
hello, i am a PHP newbie and i am stumped by the problem below and would appreciate any thoughts: if i am submitting my HTML form to a PHP script, i am asked to do something like the below, for multiple selection elements: HTML file: <form action="test.php" method="post"> <select name="testvar[]" multiple> <option>opt1</option> <option>opt2</option> <option>opt3</option> <option>opt4</option> <option>opt5</option> </select> <br> <input type="submit"> </form> then, in my test.php i am supposed to be able to access these form elements using the $_POST global. that works for non- -multiple choice elements, but for multiple choice elements such as the above the values are repeated! for example, if i chose "opt1" and "opt2" above, and in the PHP script i access it as below: $_POST['testvar'] then the array that is returned by the above access has 4 elements not 2! count($_POST['testvar']) => 4 $_POST['testvar'] => ('opt1', 'opt2', 'opt1', 'opt2') sometimes things get even worse with the value of a hidden element being added to one of these arrays! could it be the browser messing up on encountering the '[]'? i have tested on mozilla-1.0rc1 and netscape-4.7. i am running apache2 with php4 on freeBSD 4.3. any ideas? thanks, --ravi

« previous php.general (#96816) next »