How To Send Email With Perl, Part II
By Will Bontrager2004-06-09
2. Checking For Required Fields
If a form is used to submit information to the script, it can have a hidden field name="required" with a value containing the field name(s) that are required to have information before the form can successfully be submitted. If more than one form field name is required, separate them with a comma. Example:
<input type="hidden" name="required"
value="firstname, email">
The subroutine CheckRequired ensures that all required form fields contain information. The subroutine also uses another subroutine, ValidEmail, to verify that the email address stored in $In{email} is a validly formatted address. If appropriate, subroutine CheckRequired presents an error message to the user.
Subroutine WebPageErrorMessage is where error message web pages are sent to the user's browser. You'll notice that the last line of the subroutine is
goto BOTTOM;
That lines tells the script to jump to the label named "BOTTOM" located near the bottom of the script. (The label could be named anything you please. By convention, it is all capital letters. I chose "BOTTOM" simply because it is descriptive of where the label is located.)
The goto label method is used instead of the exit() function so the script can run within mod_perl.
Tutorial Pages:
» How To Send Email With Perl, Part II
» Overview
» 1. Form Field Values
» 2. Checking For Required Fields
» 3. Sending the Email
» 4. The ThankYou Page
» An Example Auto-responder's Web Page Form
» Still To Come
Copyright 2004 Bontrager Connection, LLC
| Related Tutorials: » Random subroutines in Perl » Log Script Use » Creating Perl Modules for Web Sites » Bit Vector, Using Perl Vec » Build a Perl/CGI Voting System » Perl Range Operator |
