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 IamaSherpa 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 Array to a Form without Losing Data

Status
Not open for further replies.

bmcc

Technical User
May 31, 2002
10
US
In the following test2.html code user does multiple selection. When Submit is pushed,the selections are passed correctly to an array in test2.pl. (e.g. cis100cis200) However, if I pass this array in test2.pl to test3.pl as a hidden filed as a hidden field, only the first entry out of the selection is received by the array in test3.pl. (e.g. cis100) I wonder how to fix this problem ? Thanks.

file name: test2.html
<html>
<body>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;/cgi-bin/test2.pl&quot;>

<select name=&quot;class&quot; size=&quot;4&quot; multiple>
<option value=&quot;cis100&quot;>CIS100</option>
<option value=&quot;cis200&quot;>CIS200</option>
<option value=&quot;cis300&quot;>CIS300</option>
<option value=&quot;cis600&quot;>CIS600</option>
<option value=&quot;cis700&quot;>CIS700</option>
</select>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;>
</form>
</body>


#file name: test2.pl
use CGI qw:)standard);
print &quot;Content-type:text/html\n\n&quot;;
@class= param('class');
print &quot;<html><body>&quot;;
foreach $a (@class)
{
print &quot;$a<br>&quot;;
};
print <<EndForm;
<form name=&quot;test2&quot; method=&quot;post&quot; action=&quot;/cgi-bin/test3.pl&quot;>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;>
<input type=&quot;hidden&quot; name=class value =@class>
</form>
EndForm
print &quot;</body></html>&quot;;

#file name: test3.pl
use CGI qw:)standard);
print &quot;Content-type:text/html\n\n&quot;;
@class= param('class');
print &quot;<html><body>&quot;;
foreach $a (@class)
{
print &quot;$a<br>&quot;;
};
print &quot;</body></html>&quot;;

 
print <<EndForm;
<form name=&quot;test2&quot; method=&quot;post&quot; action=&quot;/cgi-bin/test3.pl&quot;>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;>
<input type=&quot;hidden&quot; name=class value =@class>
</form>
EndForm


print &quot;<form name=\&quot;test2\&quot; method=\&quot;post\&quot; action=\&quot;/cgi-bin/test3.pl\&quot;>&quot;;
print &quot;<input type=\&quot;submit\&quot; name=\&quot;submit\&quot; value=\&quot;Submit\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;class\&quot; value =&quot;;
foreach (@class) {print;}
print &quot;></form>&quot;;
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
why not use javascript to genrate the 2nd form (passing the value) and they sumbit to a cgi ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Neversleep, thanks for your help.
However, your fix will pass the array in test2.pl as a string to test3.pl : $class[0] has 'cis100cis200'. Is there a way to fix it so that in test3.pl, $class[0] has cis100, and $class[1] has cis200 ?

Also, I wonder what's causing the original problem ? How to pass correctly array in first form to array in second form ?

Could you elaborate a bit more about your suggestion on &quot;using Javascript to generate form ?&quot;

Many Thanks!

 
Neversleep, thanks for your help.
However, your fix will pass the array in test2.pl as a string to test3.pl : $class[0] has 'cis100cis200'. Is there a way to fix it so that in test3.pl, $class[0] has cis100, and $class[1] has cis200 ?

Also, I wonder what's causing the original problem ? How to pass correctly array in first form to array in second form ?

Could you elaborate a bit more about your suggestion on &quot;using Javascript to generate form ?&quot;

Many Thanks!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top