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

Stephane Bortzmeyer bortzmeyer@netaktiv.com
Mon, 7 May 2001 15:48:37 +0200


I made many HTML forms with Zope but now, I need checkboxes. If I try:

<FORM action="handleForm">
<INPUT TYPE="checkbox" NAME="sugar" CHECKED>Sugar?&nbsp;
<INPUT TYPE="checkbox" NAME="milk">Milk?<BR> 
<INPUT TYPE="submit" NAME="submit" VALUE="Order">
</FORM>

The Python Script handleForm cannot run if Milk is unchecked. This is
because HTML browsers only send the value of the checkbox if it is
checked. The URL sent looks like:

http://progress.netaktiv.com:9673/Tests/handleForm?sugar=on&submit=Order

(do note there is no Milk)

and the error message is:

---------
Site Error

An error was encountered while publishing this resource. 

Invalid request The parameter, milk, was omitted from the request.

Make sure to specify all required parameters, and try the request
again. 
---------

Of course, milk is in the parameters of the Python Script, but how can
I say that it is optional and should default to false? Using
"milk:boolean" as its name changes nothing.



 Zope 2.3.2 (source release, python 1.5.2, linux2)