programming-examples/perl/CGI/Generate and Process Forms.pl

25 lines
767 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/bin/perl
use warnings;
use CGI::Pretty qw(:all);
use strict;
print header();
if (param('first') and param('last')) {
my $first=ucfirst(lc(param('first')));
my $last=ucfirst(lc(param('last')));
print start_html("Welcome"),h1("Hello, $first $last");
} else {
print start_html(title=>"Enter your name");
if (param('first') or param('last')) {
print center(font({color=>'red'},"You must enter a",(param('last')?"first":"last"),"name"));
}
print generate_form();
}
print end_html();
sub generate_form {
return start_form,
h1("Please enter your name:"),
p("Last name", textfield('last')),
p("First name", textfield('first')),
p(submit),
end_form;
}