[TFW] Re: [Zope] Form Data Needed in Second Form

Itai Tavor itai@optusnet.com.au
Wed, 1 May 2002 17:23:28 +1000


>At 03:41 PM 5/1/2002 +1000, Itai Tavor wrote:
>>>Dan Shafer wrote:
>>>
>>>I have part of a Zope app written largely as Python scripts linking DTML
>>>forms that looks conceptually like this:
>>>
>>>1. Form A gathers data and then as its action invokes a Python script.
>>>2. Python Script 1 creates a new DTML document and updates its contents
>>>based on field data in Form 1.
>>>3. Python Script 1 then uses RESPONSE.redirect() to open a second DTML
>>>form, Form 2.
>>>4. Form 2 needs the name of the document Python Script 1 created as well as
>>>access to some or all of the data in the fields in Form 1.
>>>
>>>What is the best/right/only way to accomplish this goal?
>>>
>>>Seems like it should be straight-forward but I've played with several
>>>promising ideas that turned out to be dead ends. I'm getting a bit 
>>>desperate.
>>>
>>>All help appreciated!
>>
>>My preferred solution is to call Form 2 in the context of the new 
>>document. Your Python Script creates 'doc1' and then redirects to 
>>'doc1/Form2'. Form 2 then has full access to all the data stored in 
>>the new document.
>
>Good idea. But won't this require me to parse the contents of doc1 
>rather than simplly grabbing the data from the Form1 POST operation? 
>I can do that, I suppose, but it seems inelegant somehow. There must 
>be a more efficient way, no?

You're right. I usually use this solution when the submitted data 
gets stored in properties, which makes it easy to access in the 2nd 
form. If you somehow incorporate the data into the content of the 
document, you probably don't want to have to parse the content.

In this case I'd try one of two other solutions - if the amount of 
data is small, you can add it to the URL you redirect to. Something 
like 
"Form2?form1data.newid:record=doc1&form1data.someparam:record=somevalue". 
Then in Form 2 REQUEST['form1data'] should give you a dictionary with 
your data in it. The other option is not to redirect to Form 2 but to 
return it from the Python Script (untested, YMMV, this may kill your 
dog, etc.):

     # Create and fill new document
     ....

     # Collect all the data needed by Form 2
     dict = {}
     dict['new_id'] = new_document_id
     dict['some_param'] = REQUEST['form']['some_param']

     # Render Form 2
     return context.Form2(context, REQUEST, form1data=dict)

If I was doing this, I'd use the 2nd option. Much cleaner.

Hope this helps more than the last suggestion.
-- 
--
Itai Tavor                      -- "Je sautille, donc je suis."    --
itai@optusnet.com.au            --               - Kermit the Frog --
--                                                                 --
-- "If you haven't got your health, you haven't got anything"      --