[Zope] Returning and showing value of a checkbox

Dylan Reinhardt Dylan@DylanReinhardt.com
Tue, 21 Jan 2003 17:54:31 -0800


At 05:02 PM 1/21/2003, Don Brooksby wrote:
> > I have even tried to do:
> > <td><input type="checkbox" name="newmain" value="<dtml-var main>"></td>

Checkboxes don't have a value attribute.  They are either checked or not 
checked.

Your two options are:

<input type=checkbox name=whatever checked>
<input type=checkbox name=whatever>

That's all they do, other attributes will be ignored.

In your template file, insert the string "checked" into your tag if the 
value corresponding to this box is true.  If it isn't, don't.  The code to 
do that in DTML and ZPT was posted earlier.

When you process the form, use something like the following to get the 
value of your checkbox:

my_box_value = REQUEST.form.get('my_checkbox_name', 0)

If the box isn't checked, the name of the box may not be posted to your 
processing script.  In that case, get() provides a not-found value of zero, 
corresponding to a "false" value you'd want to have received from an 
un-clicked checkboxes.

Does that help?

Dylan