As of ContactForm version 1.3, the look and feel is controlled via a simple template system. A template is simply an HTML file with four variables that get replaced with content by Contact Form.
- $title -- the title of the page
- $css -- style rules that control how the form looks
- $content -- the form itself
The default template is very simple:
Contact form comes with standard name, address, subject and message fields. It is very easy to add
additional fields. There are several unused examples included in the contact form configuration. When you add additional field you need to add them to the @FormFields list.
# A regular expression describing a properly formatted field.
# Uses on of the included pre-canned types as enumerated below
'required' => $PHONE_OPTIONAL,
# What to display to the user when the field is not filled in correctly
'error' => 'The phone number you entered does not appear to be valid.',
# Type of the field, this will display as a free form entry text box
# Other types such as selects, text areas, and radio buttons are available
'type' => 'text',
# Text to display next to the field for the user
'description' => 'Phone Number:',
There are plenty of prebuilt regular expressions to choose from:
- $SOMETHING - A generic required field (multiple line textarea)
- $ANYTHING - A generic optional field (multiple line textarea)
- $ONE_LINE_REQUIRED - A generic required field (single line text field)
- $ONE_LINE_OPTIONAL - A generic optional field (single line text field)
- $ZIPCODE_REQUIRED - Required postal code.
- $ZIPCODE_OPTIONAL - Optional postal code.
- $PHONE_REQUIRED - Required phone number.
- $PHONE_OPTIONAL - Optional phone number.
- $EMAIL_REQUIRED - For a required email address
- $EMAIL_OPTIONAL - For an optional email address
- $PRICE_REQUIRED - A required price (number with two decimal points)
- $PRICE_OPTIONAL - An optional price (number with two decimal points)
- $FLOAT_REQUIRED - A number, possibly with decimal points
- $FLOAT_OPTIONAL - A number, possibly with decimal points (optional)
- $INTEGER_REQUIRED - A number without decimal points
- $INTEGER_OPTIONAL - A number without decimal points (optional)
- If you know regular expressions you can make up your own
Changing this will prevent other sites from linking to your contact form. You would want to consider this especially if some other site sets up a button that allows users to click the button to immediately send you a prefilled email - effectively spamming you with the same message over and over.
Other email forms have hyped this as a security feature. However this method cannot prevent a specially designed program from automatically sending email through your server. Contact form hides email addresses makes the form much less of a target for such spammers because they cannot use it to send email to just anybody.
It would be possible to change the character set used in contact form from Latin 1 (ISO-8859-1) to
Unicode (UTF-8) or something else that can handle characters in a wider variety of languages. To
do so simply modify the my $charset variable.
that makes sure the form elements are valid before submission. Contact Form also does a server side
check, so this is not needed (in fact some browsers can't handle it and Contact Form doesn't make
them do the check). You might want to turn this off if you don't want users to be able to look
at the source of the page and figure out what patterns you actually would accept for certain fields.
Contactform now has the ability to do drop down lists. To set up a selection field and its options, you need to do two things. First, in the Form_Type variable, set the field to "select". Second, in the Form_Fields variable set the regular expression for the field to be a pipe separated ('|') list of options. The "state" field is done for you as an example. The 50 states are given as options and the user can select their state from a pull down list. If your options have spaces in them, they should be enclosed in parenthesis like so: "(Option one)|(Option two)|(Option three)". Punctuation is not supported in options, stick to only letters, numbers, and spaces.
Contact form can be difficult to upgrade if significant configuration changes are made directly in contact.pl. Contact form supports an external XML configuration file for all possible configuration options. An example configuration is included with the download.
Copyright (C) 2002-2020 Stephen Ostermiller