[ZPT] Re: Action

Martijn Pieters mj@zope.com
Wed, 19 Mar 2003 11:38:45 -0500


On Wed, Mar 19, 2003 at 05:28:20PM +0100, Tom Deprez wrote:
> <snip>
>  
> > Do you know about the :method modifier? It does exactly that; it'll
> > find a method named by the submitted form field ending in :method
> > starting at the form action.
> 
> No, didn't know about the method modifier. How do you use that in ZPT?

It has nothing to do with ZPT. It is part of the Publisher, just like the
:int and :lines modifiers.

Let's say your form's action is 'http://url/to/foo' and you have two submit
buttons named 'bar:method' and 'baz:method'.

When you click on the 'bar:method' submit button in your browser, the
browser will contact the Zope server at http://url, posting to the object
'/to/foo' all form information. That information includes a 'bar:method'
field, but not a 'baz:method' field, because you clicked the former button,
not the latter.

The publisher goes over all the fields, sees a :method modifier, and takes
the object path and atttaches the field, minus the modifier to it. So, when
the 'bar:method' field is found, the publisher will munge the path to
'/to/foo/bar'. So, it'll call the bar method on the foo object (which could
be found through acquisition).

This trick is used in various places in the ZMI; just grep for :method.

-- 
Martijn Pieters
| Software Engineer  mailto:mj@zope.com
| Zope Corporation   http://www.zope.com/
| Creators of Zope   http://www.zope.org/
---------------------------------------------