Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass an array through a form?

Status
Not open for further replies.

perlprogramming

Programmer
Joined
Mar 7, 2007
Messages
2
Location
US
I am setting up a database utility where specific engineers are assigned to various projects. Projects will be added from time to time, so it can't be hard-coded. See the code below. It simply creates a list of project names, each with its own drop-down menu with a list of engineers, allowing the user to assign all of projects a unique responsible engineer.

==========================================

print "

<form method=\"POST\" action=\"cgi/assignperson.pl\">";
<INPUT TYPE=\"hidden\" NAME=\"total\" VALUE=\"$numberofprojects\">

for ($x=0; $x < $numberofprojects; $x++) {
print "
<p>$program[$x]: <select size=\"1\" name=\"assignedperson[]\">
<option value=\"Person1\">Person1</option>
<option value=\"Person2\">Person2</option>
<option value=\"Person3\">Person3</option>
<option value=\"Person4\">Person4</option>
<option value=\"Person5\">Person5</option>
<option value=\"Person6\">Person6</option>
</select></p>
";
} # end for loop to create form drop-downs

print "
<p>&nbsp;</p>
<p><input type=\"submit\" value=\"Submit\" name=\"B1\"></p>
</form>";

==========================================

I understand that you can grab the value of a single parameter using a statement like this:

$total = $param{total};

How do I send and retrieve an array in a form, like the assignedperson[] array shown above? Any ideas?

 
Code:
use CGI qw/:standard/;
my @array = param('total');

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks for your help, but it's still not working right.

For some reason I can't get it to pass the values in assignedperson[]. I used the following:

use CGI qw/:standard/;
my @array = param('assignedperson');
foreach (@array) {
print $_;
}

Unfortunately there aren't any values passed through the form. Perhaps I'm not coding the drop-down in the form properly?

<select size=\"1\" name=\"assignedperson[]\">
<option value=\"Person1\">Person1</option>
<option value=\"Person2\">Person2</option>
<option value=\"Person3\">Person3</option>
<option value=\"Person4\">Person4</option>
<option value=\"Person5\">Person5</option>
<option value=\"Person6\">Person6</option>
</select>

Any idea what I'm doing wrong?
 
remove the [] in the select tag name:

<select size=\"1\" name=\"assignedperson\">

but that will only get one value from the drop down menu anyway as you have not defined multiple values in the select tag.

<select size=\"1\" name=\"assignedperson\" multiple>


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top