Next / Previous / Contents / TCC Help System / NM Tech homepage

3.2. Direct CGI links without use of a form

You can link to a CGI script without using an HTML form element. On the TCC web server, your script's name must end in .cgi, .py, or .pl.

Here's the general form of a CGI link. It looks just like any other link. When a user clicks on it, your CGI script will be run, and its output will be displayed as a Web page.

  <a href='whatever.cgi'>link text</a>

You can also pass information to the CGI script by appending a question mark (?) followed by a list of names and values. These name-value pairs are transmitted to the CGI script in exactly the same way as name-value pairs from an HTML form element. Here is the general form:

  <a href='whatever.cgi?name1=value1&name2=value2&...'>link text</a>

The names and values in the list must be URL-encoded:

Python's urllib module has a function called quote_plus that performs this encoding on a given string. Here is an interactive example:

>>> import urllib
>>> urllib.quote_plus('abc 123 +!@#$%^&*()|\?/_-<>')
'abc+123+%2B%21%40%23%24%25%5E%26%2A%28%29%7C%5C%3F%2F_-%3C%3E'
>>>

As with forms, it is important to coordinate the design of the CGI script with the links to it, so that the names used in the link are names that the script expects to receive.

Here's an example link:

  <a href='foo.cgi?fave=dark+green&natural=on'>Click here</a>

When the user clicks on this link, the script foo.cgi will receive two name-value pairs: