Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Answer: How do I get data from a web form (the correct way)?

by andyram27 (Initiate)
on Apr 25, 2002 at 02:22 UTC ( #161839=categorized answer: print w/replies, xml ) Need Help??

Q&A > CGI programming > How do I get data from a web form (the correct way)? - Answer contributed by andyram27

Same thing bugged the hell out of me. Here's how I do it. This program takes input from a generated form and prints it to the browser. 1. Make sure you have CGI.pm installed
#!usr/bin/perl -w #include warning switch

#loads CGI with standard shortcuts
use CGI qw/:standard/;

#good for keeping track of variable scope, etc
use strict;

my $name = param('name') || '';

if($name) {
&page2;
} else {
&page1;
}

sub page1 {
print header;
print '<\form \method="post" \action="thisfile.pl">';
print '<\input \type="text" \name="name">';
print '<\input \type="submit" \value="submit">';
print '<\/form>';
}

sub page2 {
print header;
print 'Hi, '.$name.', your variable has been submitted.';
}

  • Comment on Answer: How do I get data from a web form (the correct way)?
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2020-09-22 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (130 votes). Check out past polls.

    Notices?