On Tue, 2008-11-11 at 03:19 -0800, marys wrote: > Hello: > Can anyone tell me how to use CGI.pm's 'textfield' function to set up > a form with a lot of fill-in fields and then parse them? I tried to > read three values from input boxes but the output seems to be the name > of the textbox and not its value. Here are two scripts: > > (1) a.cgi: > > #!/usr/bin/perl -wT > use CGI::Carp qw(fatalsToBrowser); > use CGI ':standard'; > use strict; > use diagnostics; > my $z = new CGI; > print $z->header; > print $z->start_html; > > > print $z->h2("Please indicate the length of each leg of the > triangle:"),"\n"; > > print $z->startform(-method=>"POST",-action=>"action.cgi"); > > my @leglength; > my @leg; > > foreach (0..2){ > print $z->h2($leg[$_]," ",textfield("leglength[$_]")); > } I would suggest for clarity you may want to either stick to the OO style or the functional style or at least have a reason for division print $z->h2($leg[$_]," ",$z->textfield("leglength[$_]"))
> > print $z->submit('Submit'); > > print $z->end_html; > > _____________________________________________________________________________________________ > > (2) action.cgi: > > #!/usr/bin/perl -wT > use CGI::Carp qw(fatalsToBrowser); > use CGI ':standar'; > use strict; > use diagnostics; > my $q = new CGI; > my @param=param();#these are the contents from textboxes on previous > page "params" is a hash and I don't think you want to convert it to an array ("param" is a method which I don't think should be accessed this way) If you do then only the odd numbers will correspond to the values (the evens being the names/keys). I'd suggest for now you continue to just access the values through the CGI object ($q->param(...)). > print $q->header; > print $q->start_html; > > my @leglenth; > > my @param=param(); > my $z; > my $a=-1; > foreach(0..2){ > $a+=1; > $leglenth[$a] = $param[$a]; > } > > my $numelements=scalar(@leglenth); > print $q->h2("The number of elements in array [EMAIL PROTECTED] is > $numelements\n"); > > foreach (@leglenth){ > print $q->h2("\$leglenth[$_] is $_ \n"); > } > > print $q->h2("[EMAIL PROTECTED] is @leglenth \n"); > > print $q->end_html; > > _____________________________________________________________________________________________ > I illustrated the problem with just three fill-in fields, but I will > need many more. The output of the print statements in the file > 'action.cgi' is that each element listed has the name of the element, > e.g. "leg[0]" , not the value filled in. I can pass the values > through if I individually label each input box in the input script, > but it gets very sloppy and tedious to do it that way. Does anyone > know if it can be done the way I tried? > Thank you in advance. > Mary > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/