[Zope] dtml-if and checkboxes
Passin, Tom
tpassin@mitretek.org
Fri, 4 Oct 2002 16:43:22 -0400
[ Hires, Russell (CAP, CARD)]
> I'm experimenting with zope again, playing with the REQUEST=20
> object and form objects. In my latest delimma, I've got the=20
> following snippet:
>=20
> <dtml-if expr=3D"check_box =3D=3D ('on')">
> The check box is checked!
> </dtml-if>
>=20
> What I don't get: if the checkbox is checked in the form,=20
> then this works, and I get the output. If it isn't checked,=20
> then I get an error saying that the checkbox ("check_box" in=20
> the form) isn't defined. This is borne out as well by=20
> <dtml-var expr=3D"REQUEST.form">, which shows a text box's name=20
> and the value that it holds (whether it holds a value or=20
> not), and the checkbox's name and value ('on'), when it's=20
> checked. If it isn't checked, it isn't there at all. So, I=20
> guess I'm going to have to look to see whether it's there or=20
> not, right? How would I do that?
You can just test for the existence of the checkbox name:
<dtml-if "REQUEST.has_key('check_box')">
It was checked
</dtml-if>
Cheers,
Tom P