FAQ

On Jan 5, 8:33 pm, g...@lazymountain.com (Greg Jetter) wrote:
On Monday 05 January 2009 2:22:08 pm marys wrote:




Does anyone know how to set up a large number of textfields for data
input and then parse them conveniently?  In the CGI.pm book it shows
how to use the form element 'textfield' like so:
#!/usr/bin/perl -wT
use CGI::Carp qw(fatalsToBrowser);
use CGI ':standard';
use CGI::Pretty;
use strict;
use diagnostics;
my $x = new CGI;
print $x->header;
print $x->start_html;
print $x->center($x->br, $x->h1("Here are three textfields:\n"),
$x->startform(-method=>"POST",-action=>"parsnip.cgi"),
textfield(-name=>'X1',-size=>5.),
textfield(-name=>'X2',-size=>5.),
textfield(-name=>'X3',-size=>5.),
$x->p,
$x->submit( -name=>"Submit"));
print $x->endform;
print $x->end_html;
and I would like to check that the fields contain no special
characters:
#!/usr/bin/perl -wT
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard -no_xhtml);
#use CGI ':standard';
use CGI::Pretty;
use strict;
use diagnostics;
my $x = new CGI;
my $X1=param('X1'); my $X2=param('X2'); my $X3=param('X3');
if(
($X1 !~ /^[\d.]+$/) && ($X1 !~ /^\s*$/)
($X2 !~ /^[\d.]+$/) && ($X2 !~ /^\s*$/)
($X3 !~ /^[\d.]+$/) && ($X3 !~ /^\s*$/) )
{
print $x->header;
print $x->start_html(-title=>'parsnip',-bgcolor=>'silver');
print $x->font({color=>"blue"});
print $x->center( "<br>", $x->h1("Error in input!\n"),
$x->h1(" Use digits and decimal points only!\n"),
$x->h2(" Exiting!\n") );
exit;
}else{
print $x->redirect(-URL=>'done.cgi');
}
with the 'done.cgi' script:
#!/usr/bin/perl -wT
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard -no_xhtml);
#use CGI ':standard';
use CGI::Pretty;
use strict;
use diagnostics;
my $x = new CGI;
print $x->header;
print $x->start_html(-title=>'done',-bgcolor=>'silver');
print $x->font({color=>"blue"});
print $x->center( "<br>", $x->h1("Done!\n");
exit;
The problem is that if I want to collect data from lots of textfields,
like maybe 100, I get huge, sloppy scripts where I have to do a lot of
typing for the variables X1-X100 and I make a lot of mistakes.  I bet
there's a better way in the Perl world to do this.  I tried making an
array going from 1 to 100 and calling the variables "X.$_" but it
didn't work.
Is there a better way that anyone knows about?  Thank you.
use a template system like HTML::Template to create you form page , not
CGI.pm , and  process it with CGI.pm . Or use  HTML to create your form. if
your text fields are static and  won't change. Something like this you want
to separate out the  presentation of the form from the processing of the form
input.

Greg- Hide quoted text -

- Show quoted text -
Thanks, Greg. the HTML::Template looks like something that will work.
ms

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 3 | next ›
Discussion Overview
groupbeginners-cgi @
categoriesperl
postedJan 5, '09 at 11:22p
activeJan 7, '09 at 4:08p
posts3
users2
websiteperl.org

2 users in discussion

Marys: 2 posts Greg Jetter: 1 post

People

Translate

site design / logo © 2021 Grokbase