[Zope] HTML forms: how to get the value of an unchecked checkbox?

Stephane Bortzmeyer bortzmeyer@netaktiv.com
Tue, 8 May 2001 22:10:03 +0200


On Tue, May 08, 2001 at 10:07:30AM -0400,
 Thomas B. Passin <tpassin@mitretek.org> wrote 
 a message of 38 lines which said:

> > My script cannot check because parameters are apparently tested by
> > Zope before the first line of the script is executed.
> >
> I don't quite know what you are referring to here.  

When you declare parameters to a Python Script, the existence of these
parameters is tested by Zope before your script gets executed. So, you
cannot check them in your script, they have to be right in the first
place. Here is the declaration:

## Script (Python) "handleForm"
##bind container=container
##bind context=context
##bind namespace=REQUEST
##bind script=script
##bind subpath=traverse_subpath
##parameters=beverage,sugar,milk,RESPONSE
##title=
##
RESPONSE.setHeader('Content-Type', 'text/html')
if milk:
	milk = " with milk"
else:
...

> The form data is
> contained in the REQUEST object (i.e., REQUEST.form).  I assure you that all
> the form data from the checkboxes and so on will be in the REQUEST.  Zope

OK, the examples in the Zope Book (is there a better source of
information?) do not mention it, they use parameters of the script.

I cannot find REQUEST.form in the Zope API at the end of the Zope
book. But, now that I know it exists, a search in zope.org produced
severl examples. I have now a better version, where the form is 100%
standard HTML form, and the script is:

## Script (Python) "handleForm"
##bind container=container
##bind context=context
##bind namespace=REQUEST
##bind script=script
##bind subpath=traverse_subpath
##parameters=beverage,RESPONSE,REQUEST
##title=
##
RESPONSE.setHeader('Content-Type', 'text/html')
if REQUEST.form.has_key('milk'):
	milk = " with milk"
else:
	milk = ""
if REQUEST.form.has_key('sugar'):
	sugar = " with sugar"
else:
	sugar = ""
return "<P>You asked for " + beverage + sugar + milk



Funny there are so many ways to do something so simple. Thanks a lot,
I find it much better now.