[Zope3-Users] nextUrl(), passing state in formlib

Martin Aspeli optilude at gmx.net
Sun Sep 10 07:20:05 EDT 2006


Hi,

I have an add form (and later, an edit form) that may be invoked from a 
particular view among a few choices. That is, the user can be at @@foo 
or @@bar, click "add X" or "edit Y".

When the form is successfully submitted (i.e. validated) I want to send 
the user back to @@foo or @@bar depending on where they originally came 
from.

Add forms (and my custom edit handler for the edit form) have a 
nextUrl() method to work out what the next URL should be. However, I 
need to pass the state of which page I came from along the requests. 
Using HTTP_REFERER doesn't work, because when it comes to the save 
button handler, the referer is the add form I was just on.

One way would be to put a hidden field in the form that looked at the 
referer the first time it was rendered and then passed that state along 
subsequent requests. However, I really need a generalisable solution 
(there will be many of these add and edit forms for different objects). 
Having a custom pageform template for all of them (I can make them all 
use a custom base class) would be one option, but I'd rather avoid it if 
I could, since this'd need to repeat all the other code in the pageform 
that I'd rather not have to keep manually in sync when the original 
version changes or bugs are fixed.

Is there some other way of passing this kind of "where did I originally 
come from" information along?

Martin



More information about the Zope3-users mailing list