Bug #4110: getting arrays from a form

From: Date: Tue, 11 Apr 2000 21:57:45 +0000
Subject: Bug #4110: getting arrays from a form
Groups: php.dev 
Request: Send a blank email to php-dev+get-17821@lists.php.net to get a copy of this message
From: fuf@fuf.sh.cvut.cz Operating system: linux-2.2.x PHP version: 3.0.13 PHP Bug Type: Other Bug description: getting arrays from a form hello php developers! i've come across a rather debatable behaviour of PHP getting array variables from a form. let's have a html form with multiple selection list: form.html: <html> <body> <form name='aform' method="post" action="process_form.php3"> <select name="n_sas"size=10 MULTIPLE> <option value=1>option 1</option> <option value=2>option 2</option> <option value=3>etc.</option> </select> </form> </body> </html> the php3 file could then be: process_form.php3: <? echo "number of elements in n_sas is " . count($n_sas) . "<br>\n"; ?> this will print 1 ($n_sas is not an array according to php). okay, so i change the name of the variable in the form.html file to 'n_sas[]': ... <select name="n_sas[]" size=5 MULTIPLE> ... in this case php will consider $n_sas as an array and all its items will be accessible. all is fine, BUT: 'document.aform.n_sas[]' is NOT accessible from javascript! if the name is 'n_sas', obviously the selection list is accessible from the javascript (via document.aform.n_sas) but PHP won't make it an array and the variable $n_sas will have the value of the last selected option. IMO, that's not a correct behaviour. thanks for your time, Michal

« previous php.dev (#17821) next »