php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4110 getting arrays from a form
Submitted: 2000-04-11 17:57 UTC Modified: 2000-04-11 18:28 UTC
From: fuf at fuf dot sh dot cvut dot cz Assigned:
Status: Closed Package: Other
PHP Version: 3.0.13 OS: linux-2.2.x
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fuf at fuf dot sh dot cvut dot cz
New email:
PHP Version: OS:

 

 [2000-04-11 17:57 UTC] fuf at fuf dot sh dot cvut dot cz
 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-04-11 18:28 UTC] rasmus at cvs dot php dot net
This is a FAQ - use the form elements numerical index instead of the full element name from Javascript.
 [2011-08-11 23:49 UTC] jmichae3 at yahoo dot com
Michal - try putting a space in name="n_sas"size=10
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 01:01:34 2025 UTC