[Zope] Using Form data values in ZSQL Method: I must be missing something here

Thomas B. Passin tpassin@mitretek.org
Tue, 19 Feb 2002 13:44:15 -0500


[Howard Hansen]

> Thanks Eric (and Neil), passing REQUEST to zsql_method works.
>
> Here's what I had to do to get it working:
>
>     zsql_method gets a parameter named request.
>
>     Call the query with <dtml-call "zsql_method(request=REQUEST)">
>
>     Inside the zsql_method, get the form values out with calls like this:
>
>     <dtml-sqlvar "request.field_companyname" type=string>
>         or
>     <dtml-sqlvar "request['field_companyname']" type=string>
>
> I'm still confused about my confusion.  It looks to me like the
zsql_method
> has its own REQUEST and thus doesn't try to find the values in the calling
> object.  I find it odd that I haven't seen any discussion of this issue in
> any of the books/documentation I've run across.  But when acquisition does
> work inside ZSQL Methods, it's very cool!
>

Zope methods, including zsql methods, have no namespace of their own.  When
you invoke one like this from a dtml document, Zope sends it the document's
namespace, which includes the REQUEST and all its properties:

<dtml-var theMethod>

However, if you call it using a Python invocation, things are different;

<dtml-var "theMethod()">

Now it does not receive any namespace or variables, and so it cannot find
them.  You could pass in any specific parameter by writing

<dtml-var "theMethod(companyname=REQUEST.field_companyname)">

(or better to use <dtml-sqlvar> for a zsql method)

Or you can pass in the whole REQUEST as you did.

Cheers,

Tom P