Formatted Emails using eform.cgi

To have your emails from eform.cgi formatted, you have to do just two extra steps:

  1. Create a template file using TextWrangler or BBEdit or Notepad. This is just a plain text file (like an HTML file or an email message) except that there are marked places for the values of the inputs to be put in. Here's an example:
    The person's name is %%NAME and their age is %%AGE ...
    

    The double percent sign marks a place where an input will be substituted and it's followed by the name of the input. Of course, this template would only make sense for a form with inputs named NAME and AGE. (The matching is not case sensitive.)

  2. Add another hidden input to the form to specify the name and location of the template file. This is a relative pathname (like a relative URL, but on the same server, so we don't need anything except the directories and filename). If the template is in the same directory as the form (the usual case), all you need to do is give its name, such as:
    <input type="hidden" 
           name="template" 
           value="my_template.txt">
    

Here's a version of the example form using this template.

Exercise 2

Try the example form that uses templates. Next, using "view source," find out the name of the template file. Then, click here to see the template file . You can save the file if you like, but it's not necessary.

Here is the solution to Exercise 2

Unused Parameters

Using the template feature opens you up to a new set of possible errors. This section discusses what some of them are and possible causes and cures.

You may get an error message that says:

Error: Unused parameters

The following parameters were in your form, but were not used by the template file:

input 1value 1
input 2value 2

This happens when you're using a template file and eform.cgi thinks your template file is incomplete: it's not using up all the inputs. The purpose of this is so that the form author doesn't accidentally forget some important data. The error can be caused by several things:

© Computer Science 110 Staff
This work is licensed under a Creative Commons License
Date Modified: Wednesday, 24-Jan-2007 01:27:13 EST