[Zope] How to get results from form with variable number of inputs

Gustin Kiffney Gustin Kiffney" <Gustin_Kiffney@fd.org
Thu, 06 Jan 2000 10:22:08 -0500


This is a repost but it was originally posted during the holidays, so
I'm hoping it was the distraction of fun&food that caused no replies,
not the stupidity of the question!  (i'm still hoping..)

I saw in zope.org's Documentation/How-to's an essay on how to create a
form with a variable number of inputs  - the problem being, you get your results
but what are their names?  But this scheme seemed a bit too
complicated for my simple mind.  I also read about the ':record' type
but its behavior doesn't seem useful in this case where some selections
in some rows might be left empty.  What I have is a table that has 
variable number of rows with listboxes of the same choices and text
input boxes in each row (the values of the listboxes, etc being generated 
from a SQL method).
The user might change some or none of the
choices.  So what you get in the REQUEST for each form input name is a list of
values instead of a single value.  What I wound up doing to get this is in each
row having something like

<td><select name="lister:list" size="1">
<option value="Unassigned_Investigator">
<dtml-in get_all_inv_names>
  <option value="<dtml-var lastname"><dtml-var lastname></option>
</dtml-in>
</select>
</td>

which just means I coerced the 'lister' selection to be a list(in case
there were just one selection - the normal behavior for Zope when
several form variables have the same name 'joe' appears to be to turn
them into a list named 'joe'.

I also have a hidden field of 'ids' which is also a list and which is
in each row too.

So far when I get these list of 'ids' and 'lister' back, using Linux
Netscape 4 and Windows IE 4, they match up - in other words, the first
'ids' corresponds to the first 'lister', etc.  So I can figure out which
selection goes with which record/row.

So it seems that inputs with the same name are sent back to Zope 'in
order' at least with the browsers I use.  Is this a browser-dependent
thing or does Zope have some magic I don't know about that's doing
this?  Is my ignorance showing? (don't answer that!) I have a bunch more
forms I'm considering doing this way but I'm worried I'm just getting
lucky and this might not work in all situations/browsers.  Anyone know?