NAME

FormMail.pl - Handle HTML forms and mail the results


SYNOPSIS

  http://server/cgi-path/FormMail.pl?FormURL=relative_form_URL


REQUIREMENTS

This program requires Perl version 5.004. It uses the CGI, HTML::Parser and Net::SMTP (part of the libnet library) modules, and parts of the libwww-perl library.


DESCRIPTION

The FormMail program acts differently on being called with the GET and the POST request method.

When called using the GET request method (like above), it takes as its parameter (named FormURL) a relative URL containing a HTML form, retrieves it, mangles it (this includes redirecting the FORM ACTION to itself) and sends it to the client.

When the form is then submitted (with the POST request method), FormMail checks the values entered against policies layed down in the HTML form file, and either re-sends the form (inserting already filled out fields with the values entered), or sends an E-Mail to the address specified in the FORM ACTION and optionally redirects the browser to another URL.


COMMANDS

Commands to direct FormMail's processing are integrated into the HTML form file as comments of the form <!--!command!parameter-->.


Commands governing the requirement of input fields being filled out

All of the following commands remain in effect until the next such command is read. An implicit not_required command is assumed at the top of the form (this default is configurable; see below under $default_is_required).

required

All input fields up to the next requirement command are marked as required, i.e. are checked to have a non-empty contents. The parameter is ignored.

not_required

All input fields up to the next requirement command are marked as optional, i.e. are not checked. The parameter is ignored.

required_if

The parameter must have the form name eq value or name ne value.

All input fields up to the next requirement command are marked as required, i.e. are checked to have a non-empty contents, if the input field name's value is (not) equal to value.

not_required_if

The parameter must have the form name eq value or name ne value.

All input fields up to the next requirement command are marked as optional, i.e. are not checked, if the input field name's value is (not) equal to value.


Commands governing the mailing process

sender

parameter must be of the form user@domain.name. It is used for the From: header field in the E-Mail.

subject

parameter is used as the Subject: header field of the E-Mail.

pre_results

The contents of parameter is sent with the E-Mail, in front of the list of form field name/value pairs.

post_results

The contents of parameter is sent with the E-Mail, behind the list of form field name/value pairs.


Miscellaneous commands

process

The parameter is the filename of a perl script (residing in FormMail's own directory) which defines a FormMail::process routine. This routine is called after all parameters have been verified and before the mail is sent. The routine is called with two parameters: An array reference containing the field names, and a hash reference containing the values of the form fields. If FormMail::process wants to insert any new fields into the mail sent, it can do so by inserting the name into the array, and the value into the hash. It can signal the outcome of the processing by its return value: If it returns a false value, the form will be resent, with the text of the only_if_process_fails command inserted.

success_url

The parameter is the URL that the browser is redirected to if sending the E-Mail was successful.

failure_url

The parameter is the URL that the browser is redirected to if sending the E-Mail was not successful.

only_if_first_time

The contents of parameter is sent as text, if FormMail is called with the GET request method (which is the usual way it is called before processing).

only_if_missing_required

The contents of parameter is sent as text on re-sending the form (that is, if FormMail is called with the POST request method - which happens when the form gets submitted), and required input fields have not been filled in.

only_if_process_fails

The contents of parameter is sent as text on re-sending the form (that is, if FormMail is called with the POST request method - which happens when the form gets submitted), and the process file returned false.


CONFIGURATION

Near the top of FormMail.pl is a configuration section with the following entries:

$mailHost

The IP address or host name of the mail host to try and send the mail to.

$webmaster

A mail address to turn to in case of problems. This should be a mail address of someone responsible for the site, and is incorporated as a LINK REV="MADE" tag into the HEADs of all HTML pages sent.

$failFile

A filename to save the mail to, in case the mailing process failed.

$default_is_required

What to assume at the top of a form: required (1) or not_required (0).

$debug

If this variable is defined, it is taken as a filename to redirect STDERR to (in append mode).

$cgi_save

If this variable is defined, it is taken as a filename to CGI::save the received form variables to. When debugging interactively, setting the environment variable FORMMAIL_DEBUG to a true value will cause FormMail to read the file, and populate parameters passed from it.


RESTRICTIONS


COPYRIGHT

Copyright (c) 1999 Martin Vorländer. All rights reserved. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.


BUGS

None that I know of... of course, there will be some. I'd appreciate any feedback.


CREDITS

This program relies heavily on the following modules, and owes much to their authors:

Many thanks also go to the Perl UseNet community and Larry Wall.


REVISION LOG

  0.9 (17-Jan-1998)
    Initial version released
  1.0 (02-Jan-1998)
    Reworked for presentation at the German Perl Workshop 1.0


AUTHOR

Martin Vorländer <mv@pdv-systeme.de>