[Zope] Passing information from a form to an SQL method via a DTML metho dd

chas panda@skinnyhippo.com
Tue, 28 Sep 1999 00:30:45 +0800


>What I want to know is this: how do I perform the following tasks (I've had
>a look in the DTML user's guide and can't find anything to help me):
>
>1. Pass data as an attribute/property/parameter from a DTML document to a
>DTML method and hence to a ZSQL method. Do I need to set up some variables,
>populate them with my data, and pass them to the DTML method which then
>passes them to the SQL method?
>2. Glean data from a query and pass that too (example. We know who the
>logged in user is, via AUTHENTICATED_USER.name; this is a key in the USERS
>table in the database and I want to look up the user_id and insert that, not
>the textual name)
>3. Pass the current date/time; I can get it, like this: <dtml-var ZopeTime
>fmt="rfc822">. How do I squizz this along to the query?

I believe that the solution to all of this (definitely your first example)
is to pass the variable to REQUEST. 

eg. I have a ZSQL method that takes the argument 'category'
    The ZSQL method is called by DTML method. The DTML method has
    a variable 'category' (which could come from a DTML document -
    perhaps submitted from a form; or from a property - you 
    mentioned using the ZopeTime)
    However, the ZSQL method will fail claiming that the variable
    'category' does not exist.

Is this the type of problem you encounter ?

If so, I do pass the variable to the REQUEST object in the DTML
method before calling the ZSQL method. 

<dtml-call "REQUEST.set('category', category)">

Then call the method :
<dtml-in ZSQL_methodname size=10 start=query_start>

Why I have to do this I'm not quite sure, especially when the variable
should already exist in REQUEST if it was submitted from a web form, 
but when all else fails I just shove stuff into REQUEST (yeah, I'm
the sort of person who had 240 global variables).

Does this help ?

>Alternatively, am I completely missing the point here?

No, I think you're just discovering how convoluted/complicated this namespace
thing is ... detrimentally so, imho.  

>Many thanks in advance

Well, hope it helps.

chas

ps. returning to your first sentence :

>What I want to know is this: how do I perform the following tasks (I've had
>a look in the DTML user's guide and can't find anything to help me):

don't worry - it wasn't in there. I think everyone has had to work 
this out for him or her self :(