#!/usr/bin/perl -wT
use strict;
use CGI;
use CGI::Carp qw( fatalsToBrowser );
my $q = new CGI;
my $colon = ":";
my $f_name = "";
my $f_name_error = "";
my $f_email_error = "";
my $f_mail_address = "";
my $f_mail = "";
my $f_mail_error= "";
my $f_city = "";
my $f_city_error = "";
my $f_state = "";
my $f_state_error = "";
my $f_zip = "";
my $f_zip_error = "";
my $f_share = "";
my $f_shareword = "";
my $f_email = "";
my $p_Terrors = 0;
my $f_contact = "";
print "Content-type: text/html\n\n";
# If the first time the form is shown, then ...
if ($q->param == 0)
{
&S_Show_Form();
exit();
}
else
{
# If this is not the first time the form is shown.
#1. Get the value for the control named f_name.
$_ = $q->param("f_name");
s/^[\s]*//; #Remove leading blanks.
s/[\s]*$//; #Remove trailng blanks.
$f_name = $_;
$p_Terrors = 0;
#3. Check each form field for errors.
if ($f_name eq "")
{
$f_name_error = "Name may not be blank.
\n";
$p_Terrors = $p_Terrors + 1;
}
$_ = $q->param("f_email");
s/^[\s]*//; #Remove leading blanks.
s/[\s]*$//; #Remove trailng blanks.
$f_email = $_;
if ($f_email eq "")
{
$f_email_error = "Email may not be blank.
\n";
$p_Terrors = $p_Terrors + 1;
}
$_ = $q->param("f_mail_address");
s/^[\s]*//; #Remove leading blanks.
s/[\s]*$//; #Remove trailng blanks.
$f_mail_address = $_;
if ($f_mail_address eq "")
{
$f_mail_error = "Address may not be blank.
\n";
$p_Terrors = $p_Terrors + 1;
}
$_ = $q->param("f_city");
s/^[\s]*//; #Remove leading blanks.
s/[\s]*$//; #Remove trailng blanks.
$f_city = $_;
if ($f_city eq "")
{
$f_city_error = "City may not be blank.
\n";
$p_Terrors = $p_Terrors + 1;
}
$_ = $q->param("f_state");
s/^[\s]*//; #Remove leading blanks.
s/[\s]*$//; #Remove trailng blanks.
$f_state = $_;
if ($f_state eq "")
{
$f_state_error = "State may not be blank.
\n";
$p_Terrors = $p_Terrors + 1;
}
$_ = $q->param("f_zip");
s/^[\s]*//; #Remove leading blanks.
s/[\s]*$//; #Remove trailng blanks.
$f_zip = $_;
unless ( $f_zip =~ /\d{5}/ )
{
$f_zip_error = "Zip code cannot be blank and must be 5 digits in length.
\n";
$p_Terrors = $p_Terrors + 1;
}
#4. When all done checking individual form fields for errors, see if the count of errors = zero.
if ($p_Terrors == 0)
{
#No errors. Call subroutine "S_Process_Form"
&S_Process_Form();
}
else
{
#We had one or more errors, Show the form again.
&S_Show_Form();
}
} #End if $q == 0
exit();
#---------------
sub S_Show_Form {
#---------------
print "\n";
print "