Department of Computing

Local Navigation

COMP249 Web Technology

Practical - Week 6

The aim of this practical session is to give you experience with forms, Python and CGI scripting.

Before all, make sure that you know where to create your CGI scripts and how to run them. All your scripts must be stored in platypus and run from there. There is an information page about personal web publishing on Platypus. Basically, put your script in your html/cgi-bin subdirectory and make sure anyone can read or execute it with chmod 755 script.py. Note that HTML documents need to go in the html directory, if they are in the cgi-bin directory the server will try to execute them.

Processing a Form

Write an HTML document to create a form with the following capabilies:

  1. A text widget to collect the user's name
  2. Four checkboxes, one each for the following items:
    1. Four 100-watt light bulbs for $2.39
    2. Eight 100-watt light bulbs for $4.29
    3. Four 100-watt long-life light bulbs for $3.95
    4. Eight 100-watt long-life light bulbs for $7.49
  3. A collection of three radio buttons that are labeled as follows:
    1. Visa
    2. MasterCharge
    3. Discover

The form should be stored in your html folder and have cgi-bin/cost.py as its action.

Firstly, save the following Python script as cost.py it illustrates the use of cgi.test() which can be a useful tool for debugging form submission

#!/usr/local/bin/python

import cgi
import cgitb; cgitb.enable()

cgi.test()
      

Submit your form and make sure you understand (most of) the output of the script.

Now modify cost.py that computes the total cost of the ordered light bulbs and the part of it that is GST (10%). The program must inform the buyer of exactly what was ordered, in a table.

Data Validation

Write an HTML document to provide a form that collects names and telephone numbers. The phone numbers must be in the format (dd) dddd dddd. Write a CGI program that checks the submitted telephone number to be sure that it conforms to the required format and then returns a response that indicates whether the number was correct.

 

Comments to: comp249-admin@ics.mq.edu.au

Copyright & Site information