Passing information from a form to an SQL method via a DTML metho d d
I'm getting stuck with this. I have a DTML document, doc.dtml, with a form whose action, act.dtml, tells the user "thank you very much, please call again" and runs an SQL method, new.sql, which inserts data from fields a,b,c (from doc.dtml) into the MySQL database. Obviously it's not working, else I wouldn't be writing this :) 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? Alternatively, am I completely missing the point here? Many thanks in advance Peter.
Hi Peter, OK, I'll give you an example. DTML Document called doc_dtml, has a form with three fields called a,b,c respectively. <!--#var standard_html_header--> <form action="act_dtml"> <table> <tr><th align=left>A</th><td><input type=text name=a></td></tr> <tr><th align=left>B</th><td><input type=text name=b></td></tr> <tr><th align=left>C</th><td><input type=text name=c></td></tr> <tr><td></td><td><input type=submit></td></tr> </table> </form> <!--#var standard_html_footer--> DTML Document called act_dtml which calls a SQL Method to update/insert a database. <!--#var standard_html_header--> <dtml-call "dbupdate(a=a,b=b,c=c)"> Thank you for you interest. <!--#var standard_html_footer--> SQL Method called dbupdate (you are better off setting the parameters entry box to 'a:string b:string c:string') insert into test values( <dtml-sqlvar a type=string>, <dtml-sqlvar b type=string>, <dtml-sqlvar c type=string>) Once you run these three objects starting with doc_dtml you will have updated your db. HTH Phil phil@philh.org -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Peter Whysall Sent: Monday, September 27, 1999 2:01 PM To: 'zope@zope.org' Subject: [Zope] Passing information from a form to an SQL method via a DTML methodd I'm getting stuck with this. I have a DTML document, doc.dtml, with a form whose action, act.dtml, tells the user "thank you very much, please call again" and runs an SQL method, new.sql, which inserts data from fields a,b,c (from doc.dtml) into the MySQL database. Obviously it's not working, else I wouldn't be writing this :) 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? Alternatively, am I completely missing the point here? Many thanks in advance Peter. _______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope (To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
I think the real problem was due to passing from DTML document to DTML method to ZSQL method. The variables suddenly disappear from REQUEST. DTML document direct to ZSQL method works fine, as you describe very well below. chas
OK, I'll give you an example.
DTML Document called doc_dtml, has a form with three fields called a,b,c respectively.
<!--#var standard_html_header--> <form action="act_dtml"> <table> <tr><th align=left>A</th><td><input type=text name=a></td></tr> <tr><th align=left>B</th><td><input type=text name=b></td></tr> <tr><th align=left>C</th><td><input type=text name=c></td></tr> <tr><td></td><td><input type=submit></td></tr> </table> </form> <!--#var standard_html_footer-->
DTML Document called act_dtml which calls a SQL Method to update/insert a database.
<!--#var standard_html_header--> <dtml-call "dbupdate(a=a,b=b,c=c)"> Thank you for you interest. <!--#var standard_html_footer-->
SQL Method called dbupdate (you are better off setting the parameters entry box to 'a:string b:string c:string')
insert into test values( <dtml-sqlvar a type=string>, <dtml-sqlvar b type=string>, <dtml-sqlvar c type=string>)
Once you run these three objects starting with doc_dtml you will have updated your db.
HTH
Phil phil@philh.org
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Peter Whysall Sent: Monday, September 27, 1999 2:01 PM To: 'zope@zope.org' Subject: [Zope] Passing information from a form to an SQL method via a DTML methodd
I'm getting stuck with this.
I have a DTML document, doc.dtml, with a form whose action, act.dtml, tells the user "thank you very much, please call again" and runs an SQL method, new.sql, which inserts data from fields a,b,c (from doc.dtml) into the MySQL database.
Obviously it's not working, else I wouldn't be writing this :)
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?
Alternatively, am I completely missing the point here?
Many thanks in advance
Peter.
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce
For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce
For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
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 :(
participants (3)
-
chas -
Peter Whysall -
Phil Harris