[Zope] dynamic form checkbox data

Dieter Maurer dieter@handshake.de
Mon, 10 Mar 2003 22:16:51 +0100


Rua Haszard Morris wrote at 2003-3-10 13:04 +1300:
 > 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).
 > 
 > How can I generate a list of boolean values
 > representing the user's selections?  I need to use the
 > boolean value in a dtml-if in the sql that processes
 > the form data.

Say: "allCheckboxValues" is the sequence of checkbox values (they
must have different values such that you are able to distinguish
the checkboxes). You build the sequence of booleans in
"isCheckboxSelectedList".
The code looks somehow like:

    isCheckboxSelectedList= []
    for checkboxValue in allCheckboxValues:
      isCheckboxSelectedList.append(checkboxValue in ismember)


Dieter