[Zope] Dynamic HTML Forms

Eric Walstad eric@walstads.net
Fri, 17 Aug 2001 10:25:01 -0700


Hi Sean,

In the Zope Book there is a section on "Passing Parameters to Scripts" which
talks about how Zope can automagically convert form variables into lists
(and a lot of other cool things like "record" or "records").

For example, if your form looks like this:
<form name="form1" method="post" action="TheFormHandlerMethod">
  <p>Field One
    <input type="text" name="textlist:list" value="one">
  </p>
  <p>Field Two
    <input type="text" name="textlist:list" value="two">
  </p>
  <p>Field Three
    <input type="text" name="textlist:list" value="three">
  </p>
  <p>Field Four
    <input type="text" name="textlist:list" value="four">
  </p>
  <p>Field Five
    <input type="text" name="textlist:list" value="five">
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>

Note the :list suffix on the input name; this tells Zope to turn the values
into a list.

Inside 'TheFormHandlerMethod' you will have access to the 'textlist' which
is of type list:
['one', 'two', 'three', 'four', 'five']

>From there you can iterate over the list using <dtml-in textlist> in DTML
Method or "for s in textlist:" in a Script (Python)

Eric.


-----Original Message-----
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of
McMains, Sean
Sent: Friday, August 17, 2001 9:39 AM
To: 'zope@zope.org'
Subject: [Zope] Dynamic HTML Forms


Hi Folks,

We're working on a transaction processing system. At one point in the flow,
an administrator needs to see a list of all pending requests, and approve or
reject them. Since the information is all in a database, we'll be doing a
query against the database to build the form on the fly. If the first row
has a field called "value1", the second a field called "value2", etc, how do
you go about processing the results from the form when you don't know how
many fields there will be? Or is there a better approach to this problem
than naming the fields like this?

When I've done similar things in ASP, I'd pass the number of rows in the
form as a hidden field, and then use that value to iterate through the
fields. Is there something comparable to do in Zope, or is there a better
way to do this?

Still very new to Zope, so be gentle. :-)

Thanks for any help!
Sean McMains

_______________________________________________
Zope maillist  -  Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )