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

Thomas B. Passin tpassin@mitretek.org
Mon, 7 May 2001 10:22:44 -0400


[Stephane Bortzmeyer]

> <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:
>
This has been discussed in this list in the last week or two - look in the
archives.  There are several approaches:

1) Your dtml or script can check to see if that key is in the form, and act
appropriately if it is not there.
2) You can add a hidden input to the form that contains a default value for
"milk", like 'no'.  Your code checks for the presence of the value you will
get when the box is checked.

If you use method 2), name the hidden field "milk:default", then its value
will be used as the default value if the checkbox is not checked.

Cheers,

Tom P