The Practical

Creating the HTML form

Now you should create a web page containing a form.

Initially, your form should reference the CGI script which I have provided, as above, but using the POST method. Simply reference the CGI script in your <form> tag as
action='http://www.bioinf.org.uk/teaching/bbk/biocomp2/cgi/testform.cgi'

Your page should contain the following elements:

See the HTML Resources page for some help as well as the list of tags in the lecture handout.

Save your final page as form.html in your WWW directory and test that it works.

The results should look something like this:

Creating the CGI script

Having created the HTML form and tested it, you should now create your own CGI script to accept the data and print it back in some attractive format so the web-browser can display it.

Anything printed by a CGI script will be returned to the web browser. However, you must remember to start with a standard header so that the web browser knows the remaining data is HTML.

The following sample script simply prints information back to the web browser

#!/usr/bin/env python3
print ("Content-Type: text/html\n")
print ('''
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
''')

[Run script]

Hints on how to obtain data from a form and on how to create the data are contained in the CGI Resources page.

Using your knowledge of HTML, format the data so that it is attractively presented.

Save your CGI script and place it in the required directory. Ask a demonstrator for help if necessary. Alter your HTML form so that it points to the script and test your web page!

The results should look something like this:

Continue