[Zope] [Ann] emulateRedirect: emulates redirection inside Zope

Joachim Werner joe@iuveno-net.de
Wed, 2 May 2001 10:26:18 +0200


> The common task:
>
>      A user fills a form and submits it. The submitted data is checked
>      and if problems are detected, the user gets its
>      original form together with a problem indication
>      *AND* his already filled in data.
>
> is not yet well supported.
>
> A redirection to the form suffers from browser differences
> in the handling of the old request data and
> the difficulty to add all of them into the redirected
> URL.

I always used an approach like this (only works with some session management
to get persistence of course):

This is a pure example, so don't look at the details ;-)

In the form I have:

<dtml-if something_submitted>
*** check the data here, display the errors if necessary; if no errors, save
the data and redirect to the thankyou page
</dtml-if>
<form ...>
 *** in the form, the variables are all called from the session ("<dtml-var
variable missing>" to make sure there is no error if it was empty)
</form>

I call the form in the action method (by just not specifying an action). So
there is a loop until everything is fine. One could also do the same by
redirecting back to the form if there is an error found by the action
method. As long as the fields are prefilled by Zope, I don't think the
browser issue applies.

Can anybody comment whether this or the "emulateRedirect" approach is
better?

Joachim