Contact Form

Linking to Your Contact Form


Linking to the contact form on your server is very straightforward. My contact form (on ostermiller.org) is in the root directory of the webserver, so it is simply
https://ostermiller.org/contact.pl.

If your contact form is in your cgi-bin directory, the link will likely look something like this:
https://www.example.com/cgi-bin/contact.pl

If you want to link to your contact form with prefilled data, there are two ways to do so.

Append Hidden Text to Subject

I create multiple links to the same contact form from various places on my website. Because users do not always do a good job of providing a meaningful subject I like to have some idea what section of my site they came from to the contact form. I do this using the "regarding" parameter. The contents of the regarding parameter appear in parenthesis after the user entered subject in the emails that you receive. For example:
contact.pl?regarding=Moose+Tracks
contact.pl?regarding=Baking+Cookies
Use pluses instead of spaces so that all browsers handle the link correctly.

An email from a user might look like this:

From: Joe User 
Subject: I love your site!!!! (Moose Tracks)

It was the only site on the Internet I could find with the information I was looking for.
Thanks so much, and keep up the good work.

At this point you know they were talking about your moose tracking page rather than your cookie baking page.

Prefill Data

If you desire to set the subject (or any field) for the user, it is very easy to do. Simply, put a parameter with that field into your link. To error messages about incomplete forms (or to prevent the form actually being submitted if it is complete) use the prefill parameter as well:
contact.pl?subject=Loved+the+omni&prefill
contact.pl?subject=Hated+the+omni&prefill

Embed the Form in Other Pages

You may want to have the form itself as part of a larger page. To do this, you only need to copy the javascript and the form out of page source and place them on other page. The form will then submit to the contact form page. You can get by without the javascript if you remove the onsubmit="..." from the <form> tag.

Deploy Outside cgi-bin

While a cgi-bin directory is usually already configured to run scripts, you can configure any directory to run an email form using most web servers. Usually you create a .htaccess file in the directory in which you want to run the script with contents such as:

Options ExecCGI
AddHandler cgi-script .pl

Hide the .pl Extension

You may not want users to see a URL that doesn't end in .html. It is possible to hide the fact that contact form is written in perl from your visitors. You can give contact form an arbitrary extension (or even no extension at all) if you use some simple rules in a .htaccess file on Apache. Simply rename contact.pl to contact.html and use the following in .htaccess. (This assumes that your webserver is configured to use .htaccess files with the AllowOverride directive.)

Options ExecCGI
<files contact.html>
SetHandler cgi-script
</files>

Copyright (C) 2002-2020 Stephen Ostermiller

ostermiller.org (site index)