[Zope] cashing formular field values

Jim Penny jpenny@universal-fasteners.com
Thu, 1 Mar 2001 11:54:44 -0500


On Thu, Mar 01, 2001 at 05:00:26PM +0100, Andrei Belitski wrote:
> Hello!
> I dynamically create more form fields by calling a dtml method and then
> returning (refreshing the formular document which displays more fields)
> By doing it the previously introduced values of the fields disappear,
> cause I create a new form page
> Is there a possibility (may be a HTTP feature) to restore the values not
> declaring and saving each value in a separate variable?
> Thank you in advance
> Andrei

I am assuming your formular page looks like, and that init_field_count
and field_count_incr are properties available to the DTML method.

Then something like this will work

<form method=post action=.>
  <dtml-if "not _.has_key(field_count)">
    <dtml-call "REQUEST.set('field_count', init_field_count)">
  <dtml-else>
    <dtml-call "REQUEST.set('field_count', field_count + field_count_incr)">
  </dtml-if>
  <input type=hidden name=field_count value=<dtml-var field_count>

  <dtml-if "field_count == init_field_count">
    <dtml-in "range(field_count)">
      <input name=<dtml-var "'var'+_['index-sequence'])">  ...>
    </dtml-in>
  <dtml-else>
    <dtml-in "range(field_count-field_count_incr)">
      <input name=<dtml-var "'var'+_['index-sequence']"> value="<dtml-var _['var'+_['index-sequence']]>" ...>
    </dtml-in>

    <dtml-in "range(field_count_incr)">
      <input name=<dtml-var "'var'+_.str(_.int(_['index-sequence'])+field_count)">  ...>
    </dtml-in>
  </dtml-if>

  <input type=submit name=command value="Add More Fields">
  <input type=submit name=command value="Save"

</form>

This is tending twoards abuse of DTML and may be better suited for a
(Script) Python 
> 
> _______________________________________________
> 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 )
>