if information exists on form then use it in cgi

lamar_air lamar_air at hotmail.com
Mon Jul 21 21:44:54 CEST 2003

On my web form i have check boxes with the following code:

<td width="173"><input type="checkbox" name="C140" value="1.
'St.KittsNevis'">St. Kitts Nevis</td>

when the user submits the form my python cgi retreives each of the
values from the form with code like this for each:

    f=open('C:\My Documents\ABC\boxes', 'w')

    if form['C139'].value != '':

    if form['C140'].value != '':

the problem is if the user doesn't check off all the check boxes on
the form then the if form['C140'].value != '' code errors because
nothing is there.  How do i do this?

Here is the error:

The specified CGI application misbehaved by not returning a complete
set of HTTP headers. The headers it did return are:

Traceback (most recent call last):
  File "C:\Inetpub\wwwroot\Cgi-bin\Cities2.py", line 175, in ?
    if form['C139'].value != '':
  File "C:\Python22\lib\cgi.py", line 550, in __getitem__
    raise KeyError, key
KeyError: C139

More information about the Python-list mailing list