How to Make a Fill Out Form
Like Bellow's Henderson the Rain King, there is a little
voice in my head that chants without ceasing, "I want I want I want". I
saw a form and I wanted one. I wanted a bunch. I want forms that can be
used with my students: for site navigation, anonymous comments, searching
my site. I want forms that can be a playground of collaborative creation.
I want to make forms that I can sell to to earn money and buy food!
Return to the conference workshop
I. What you Need to Know and Do Before You Begin
Not all System Administrators allow people to run CGI scripts. But all
domains do have a System Administrator and this is the person you must
work with to set things up. The questions you want to ask include:
- Am I allowed to run CGI on our site?
- At some sites you must place your CGI scripts in a specially named
directory. Sometimes directory must be above
your web page directory and sometimes it can be
inside your web directory. Again, your system
administrator will specify. Usually this cgi directory is named
cgi-bin, but it may have other names.
- CGI scripts usually have to have a specific extension to the filename.
Sometimes that extension is .pl for Perl scripts and
sometimes .cgi is the file extension. And sometimes
either is fine. You can try one or the other to see if it works, or ask
your system administrator.
- You will need to know both the URL of the web page referencing the CGI
script and the absolute pathname to the script. Want to know more about
file permissions, directories and paths? This [archived at the Wayback Machine - 2009] UNIX
handout may help.
- If you are using Perl scripts, you need to specify the path to the
Perl interpreter. Scripts written in Perl require an interpreter to
execute. Most system administrators follow a convention in placing the
Perl
interpreter. You can ask your system administrator for the path, or, if
you have a shell account you can enter the following command at the UNIX
prompt to get the path.
whereis perl
- If the results of the form are to be mailed to you then you'll need to
know the path to your sendmail program. You can use the same whereis
command:
whereis sendmail
- File permissions, along with directory paths are the most common
problems with setting up CGI scripts. If you have a shell account, you can
set the file permissions from the UNIX prompt. If you don't have access to
a shell account you can set file permissions using an FTP program such as
WS_FTP [link removed - 2009]. The
UNIX
handout will give you more information about file permissions.
II Required Files
A form, such as the
[archived at the Wayback Machine - 2009] Webbish Query
requires several files:
- The web page which contains the form. The HTML form tag includes many
attributes to format various input fields, short answer, long answer,
and radio buttons and check boxes for multiple choice.
desired result.
The NCSA
Mosaic Guide to Fill-Out Forms [link removed - 2009]
includes a set of links to examples of forms.
You can learn a lot about making forms and web pages in general by
viewing the source code of web pages. Viewing the source code allows you
see the actual HTML of the page. In Netscape click on the View menu and
select "Document Source". A new window will appear which will contain the
HTML source code.
- The CGI script that is executed when the form is submitted. This
script takes the data entered in the form's fields and, depending on what
kind of script you use, emails the results to you, and/or compiles a
database and/or posts the data results to a new web page.
- You need a web page to open after the form is submitted. Generally
this page acknowledges receipt of the submitted information (i.e., "Thanks
for your input!").
- You may need a web page to report errors to the person completing the
form. In the case of my test, if a student forgets to enter her name, I
need a web page to remind her to go back and enter her name. If the form
you are using doesn't require specific information to be included, you
can omit this web page.
Creating a Query Form with AlienForm
AlienForm comes from Jon's CGI Script
archive [link removed - 2009], and is written in Perl. It's a killer script to use for
forms. It includes the basic CGI script for handling the form results, and
several small files that can be used as templates to format the delivery
of the form results to your email box and to format web pages for results
and errors.
The AlienForm page [link removed - 2009] includes
excellent instructions for downloading and configuring the script and
accompanying files.
- Acquire the CGI script and template files from AlienForm [link removed - 2009]. This link
takes you to the actual section of the page for downloading the script and
the 5 related files: alienform.txt, form.txt, mail.txt, reply.txt,
success.txt, error.txt
- Rename the file alienform.txt to
alienform.cgi or alienform.pl as
necessary for your site. Edit the file to make the changes called for on
the AlienForm web page. You will need to know:
- a. The path to your Perl interpreter
- Most system administrators follow a tradition of placing the Perl
interpreter in the path /usr/bin/perl. If you have a
shell account you can check the location of the Perl interpreter with the
command: whereis perl, and the response will be the path
statement. You can ask your system administrator for this information if
you don't have shell access (i.e., access to the UNIX prompt).
- b. The path to your sendmail program
- Like the Perl interpreter, the sendmail program is generally
available in the path /usr/sbin/sendmail, and you can
check this location with the same command used for Perl: whereis
sendmail.
- c. The path to your template files
- These template files come with AlienForm and include a file to
report errors, a file to format the data to be mailed to you and a file to
format a web page to follow the form submission. I recommend keeping the
alienform.cgi together with the associated files for organizational
purposes. At my site I can place my CGI scripts inside my web directory,
and so I've created a directory named scripts and within
that directory is a subdirectory for alienform named
alien. So my path statement reads:
/usr/users/edmiston/public_html/scripts/alien/. The UNIX
command pwd can be used to identify your directory path.
- d. The host name and IP addresses of your server
- This is a safety measure to keep people at other domains from
using your script. This entry includes both the domain name and the IP
address of your server. For example, I use:
woodfin.cs.unca.edu 152.18.18.7
Once you edit the CGI script you needn't edit it again for additional
applications.
- Once the files are in place (i.e., the CGI scripts and associated
files in one directory) and the form in the web directory, be sure to set
the file permissions. The CGI script needs to be executable and the other
files must be readable.
chmod alienform.cgi 755
chmod [all other files] 644
Now you're ready to get formal!
Some CGI and Perl Resources
[Links are probably out of date - 2009]
- The CGI
Collection
- Contains links to a number of CGI/Perl tutorials and "tips and
tricks". THis resource has been very helpful to me in the past.
-
Server Side Includes (SSI)
-
The CGI Resource is an all around useful site and their page on SSI
is
especially helpful. Some CGI scripts require SSI.
-
Perl Tutorial
- This NCSA tutorial is very detailed and well organized.
- The CGI FAQ
-
Matt's Script Archives contains a FAQ (Frequently Asked Questions)
that's excellent for troubleshooting.
Return to the conference workshop
|