FAQ
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[$_]"));
}

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
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 \@leglenth is
$numelements\n");

foreach (@leglenth){
print $q->h2("\$leglenth[$_] is $_ \n");
}

print $q->h2("\@leglenth 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

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 4 | next ›
Discussion Overview
groupbeginners-cgi @
categoriesperl
postedNov 11, '08 at 11:19a
activeNov 17, '08 at 11:14a
posts4
users3
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase