[Zope] dynamic form checkbox data

J Cameron Cooper jccooper@jcameroncooper.com
Mon, 10 Mar 2003 14:04:21 -0600

>I have a form which has (dynamically-generated)
>checkboxes (from database rows).
>these are of the form:
><input type=checkbox name="ismember:list:string"
>checked><dtml-var sequence-var-name>
>(some do not default to checked).
>When I'm processing the form data, the list contains
>data for only those that are checked (i.e. no list if
>none are checked, a short list if some are checked).
That's a tricky issue with web programming in general: a form will only 
report a value for a check box when it is checked, and otherwise will 
ignore it. There are two common ways out:

1) drop the checkbox and use radio buttons (or perhaps some other 
widget), which will guarantee a return value.
1b) add a hidden field for each question, and count an affirmative only 
when you get the hidden field and the interactive checkbox's value.

2) somehow know server-side what your questions would have been and 
compare the returned "affirmative" responses.

Number 2 is more work, but better with regards to security (you can't 
trust users to exclusively use your form) and allows you to keep your 
existing aesthetic (as opposed to #1).

I suppose there's also some monkey business you could do with 
JavaScript, but I don't really care enough to check on that.