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

Jürgen Kartnaller juergen at kartnaller.at
Sun Sep 10 10:40:07 EDT 2006


Hi Martin.

I did it this way :

The Edit Form implementation :

class AddClub(zope.formlib.form.AddForm):

     base_template =zope.formlib.form.AddForm.template
     template = ViewPageTemplateFile('club_add.pt')

...


     def referer(self):
         return    self.request.form.get('referer')\
                or self.request.getHeader('HTTP_REFERER')

     def nextURL(self):
         return self.request.form.get('referer','..')


The template ('club_add.pt') :

<div metal:use-macro="view/base_template/macros/main" >
   <div metal:fill-slot="extra_info">
    <input type="hidden" name="referer" value="" tal:attributes="value 
view/referer" />
   </div>
</div>


Hope this helps

Jürgen

Martin Aspeli wrote:
> 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