Division of Information Technology
Web Publishing @ SFSU
CGIFILE

Using CGIFILE

CGIFILE uses a template and ACTION like CGIEMAIL, but appends information to a file rather than mailing it. These directions assume that you have already created a web page form and template file using CGIEMAIL. If not, please review the Forms and CGIEMAIL documentation for directions on how to create these files.

CGIFILE uses the same reserved words as CGIEMAIL.

CGIFILE requires a file called "incoming.txt". The incoming.txt file stores the responses submitted by the form in the format specified in the template file.

Basic Steps

  1. Create a new Directory
  2. Edit the Template file
  3. Determine the Form 'Action'
  4. Create the incoming.txt file to store your data
  5. Test the Form and Template

Overview

  1. Visitors enter information into a web page form.
    In this example, the web page form is called feedback.htm
  2. The information is stored in a file called "incoming.txt"
    NOTE: This file must be called incoming.txt and must reside in the same location as the template file.
  3. A template file describes how the responses are listed in the "incoming.txt" file.
    In this example, the template file is called feedback.txt

Creating a new Directory

A new directory needs to be created for files used by CGIFILE (Later, we will give this directory write access so data can be written to the incoming.txt file). To avoid giving users access to write to your other files, these files need to be stored in a seperate directory To create this new directory you will need to log into your account using a Telnet program

  1. Login to a host such as apollo (userwww/student accounts), online (faculty only) or www (department accounts) using telnet.
  2. Using the Change Directory command (cd), change directory to public_html.

    apollo% cd public_html

  3. Using the "mkdir" command, create a directory inside public_html.
    This directory will be used to store the web page form, template file and incoming.txt file.

    In this example, the directory is called "feedback".

    apollo% mkdir feedback

  4. Copy the CGIEMAIL web page form and template file you created earlier into the new directory.

    Using the CGIEMAIL example, move the web page form "feedback.htm" and template file "feedback.txt" stored in the public_html directory to the new directory "feedback". This will need to be done in two steps.

    apollo% cp feedback.htm feedback

    apollo% cp feedback.txt feedback

  5. Change AFS file permissions to permit writing to this directory by anyone.

    apollo% fs setacl feedback system:anyuser rwl

  6. Using the change directory command (cd), change to the directory storing the files

    apollo% cd feedback


Edit the Template file

  1. Using "pico", edit the template file to use CGIFILE instead of CGIEMAIL by deleting the mail information. (To:, From: and Subject:).
    In the CGIEMAIL example, the template file is called "feedback.txt".

    apollo% pico -w feedback.txt

    The contents of the cgiemail template file look like this. The results are listed below with headings so the E-mail will be readable.:

    From: [email]
    To: userid@sfsu.edu
    Subject: Sample Questionnaire

    Group: [group]
    Year: [year]
    Term: [term]
    Major: [major]
    My comments: [comments]

    Change the cgifile template file to look like this. The results here are shown without headings -- the data is comma delimited with a single carriage return at the end of the line so it can easily be imported to another program. In this example commas are used however if the user enters commas in the text area of the form it may result in errors when importing the data into a database or spreadsheet. You can use other special characters as delimiters.

    [email],[group],[year],[term],[major],[comments]

  2. Save the changes and exit by pressing CTRL and X at the same time, press the y key when prompted to save and press return to save

Determine the Form 'Action'

In your html file (feedback.htm) replace cgiemail with cgifile

<form METHOD="POST" ACTION="/cgi-bin/cgifile/~accountname/feedback.txt">

  1. Using "pico" to edit the FORM tag in the web page.

    In the CGIEMAIL example, the web page form is called "feedback.htm".

    apollo% pico -w feedback.htm

    Using the down arrow key, scroll down until you see code similar to the following:

    <form METHOD="POST" ACTION="/cgi-bin/cgiemail/~accountname/feedback.txt">

    Edit the FORM tag to point to CGIFILE:

    <form METHOD="POST" ACTION="/cgi-bin/cgifile/~accountname/feedback/feedback.txt">

    Also, check the following:

    • Replace ~accountname with your Internet Account name
    • Add the folder name where the web page form and template file are stored. In this example, the folder is called "feedback".
    • Replace feedback.txt with the name of your template file. In this example, the template file is called "feedback.txt".

Create the incoming.txt file to store your data

  1. Using the "touch" command, create an empty "incoming.txt" file in the feedback directory.
    The incoming.txt file stores the responses submitted from the form into a format specified in the template file.

    apollo% touch incoming.txt

  2. To pickup the results/data from your form ftp the file incoming.txt to your workstation/PC.

  3. If you want to clear the information in the incoming.txt file, use the Remove (rm) command to delete the file then use the touch command to create it again. Before removing a file confirm a copy has been downloaded (all the data users have entered into the form is gone once the incoming.txt file is removed).

    Step 1: apollo% rm incoming.txt

    Step 2: apollo% touch incoming.txt


Test the Form and Template

  1. Test the web page and make sure it puts the responses into the incoming.txt file.
  2. Open a web broswer and type in the URL of your form, i.e., http://userwww.sfsu.edu/~accountname/feedback.htm.
  3. Submit your form with data at least twice.
  4. Examine the results of the incoming.txt file, this can be done by using ftp to transfer the file to your workstation/PC or by telneting to your account and using the more command to view the file in telnet.
    • apollo% more incoming.txt

      user-email@sfsu.edu,student,2000,spring,business,user-comments
      user-email@sfsu.edu,student,2000,spring,business,user-comments

  5. Verify that the results are formatted correctly and each submission is on a separate line.

About | Getting Started | Create | Publish | Enhance | Advertise | Maintain
Index | Glossary | Software | For more Information


SFSU Home   Search   Need Help?  

1600 Holloway Avenue, San Francisco, CA 94132 (415) 338-1111
Last modified May 14, 2002 by the Web Team