Using Form data values in ZSQL Method: I must be missing something here
I'm certain that I'm doing something very silly here, and I've learned many new things about Zope and databases by researching this problem, but I haven't figured out how to make it work. All I want to do is create forms that allow me to insert or update records in a database. Here's the structure I've set up: form: collects the form data, and when the user clicks submit, it calls: action_dtml_method: which calls: zsql_method, which modifies the database and tells the user what just happened When I hit Submit, I can easily list the values from the form inside the action_dtml_method, but zsql_method acts like it has no clue about the form values. It gives me the error: Missing input variable, field_companyname and the traceback: <!-- Traceback (innermost last): File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/lib/zope/lib/python/Zope/__init__.py, line 226, in zpublisher_exception_hook (Object: dir) File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/lib/zope/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: company_update) File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: company_update) File /usr/lib/zope/lib/python/OFS/DTMLMethod.py, line 195, in __call__ (Object: company_update) File /usr/lib/zope/lib/python/DocumentTemplate/DT_String.py, line 546, in __call__ (Object: company_update) File /usr/lib/zope/lib/python/Shared/DC/ZRDB/DA.py, line 486, in __call__ (Object: sqlUpdateCompany) File /usr/lib/zope/lib/python/DocumentTemplate/DT_String.py, line 546, in __call__ (Object: <string>) File /usr/lib/zope/lib/python/Shared/DC/ZRDB/sqlvar.py, line 171, in render (Object: field_companyname) Missing Input: (see above) --> I've tried using <dtml-call zsql_method>, <dtml-with zsql_method>, <dtml-in zsql_method>, and each of those using "zsql_method()" as well. I could try to pass the values explicitly, but I've used acquisition very effectively in other situations, and I'm not terribly interested in passing 29 parameters to the query. Clearly, I'm missing something fundamental, could someone please tell me what it is? Thanks! Howard Hansen http://howard.editthispage.com
Hi Howard. It looks like your ZSQL method is not getting the form data it needs. Like you mentioned, you could pass those parameters explicitly when you call the the ZSQL method, or you could pass the REQUEST object to the ZSQL method: <dtml-call "zsql_method(companyname=companyname, companyphone=companyphone, etc to the 29th parameter)"> or <dtml-call "zsql_method(REQUEST)"> Hey, you may want to try something like this - It might work and would not have to pass so much stuff to the ZSQL method: <dtml-call "zsql_method(form)"> I'm guessing it's more efficient to pass just the parameters the ZSQL method will need, but it is a pain to pass all 29 of them! I hope that helps, Eric. Howard Hansen wrote:
I'm certain that I'm doing something very silly here, and I've learned many new things about Zope and databases by researching this problem, but I haven't figured out how to make it work.
All I want to do is create forms that allow me to insert or update records in a database.
Here's the structure I've set up:
form: collects the form data, and when the user clicks submit, it calls: action_dtml_method: which calls: zsql_method, which modifies the database and tells the user what just happened
When I hit Submit, I can easily list the values from the form inside the action_dtml_method, but zsql_method acts like it has no clue about the form values. It gives me the error:
Missing input variable, field_companyname
and the traceback:
<!-- Traceback (innermost last): File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/lib/zope/lib/python/Zope/__init__.py, line 226, in zpublisher_exception_hook (Object: dir) File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/lib/zope/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: company_update) File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: company_update) File /usr/lib/zope/lib/python/OFS/DTMLMethod.py, line 195, in __call__ (Object: company_update) File /usr/lib/zope/lib/python/DocumentTemplate/DT_String.py, line 546, in __call__ (Object: company_update) File /usr/lib/zope/lib/python/Shared/DC/ZRDB/DA.py, line 486, in __call__ (Object: sqlUpdateCompany) File /usr/lib/zope/lib/python/DocumentTemplate/DT_String.py, line 546, in __call__ (Object: <string>) File /usr/lib/zope/lib/python/Shared/DC/ZRDB/sqlvar.py, line 171, in render (Object: field_companyname) Missing Input: (see above) -->
I've tried using <dtml-call zsql_method>, <dtml-with zsql_method>, <dtml-in zsql_method>, and each of those using "zsql_method()" as well.
I could try to pass the values explicitly, but I've used acquisition very effectively in other situations, and I'm not terribly interested in passing 29 parameters to the query.
Clearly, I'm missing something fundamental, could someone please tell me what it is?
Thanks!
Howard Hansen http://howard.editthispage.com
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! Thanks for the help! Howard Hansen http://howard.editthispage.com ----- Original Message ----- From: "Eric Walstad" <eric@ericwalstad.com> To: "Howard Hansen" <zope@halfmagic.com> Cc: <zope@zope.org> Sent: Monday, February 18, 2002 10:21 PM Subject: Re: [Zope] Using Form data values in ZSQL Method: I must be missing something here
Hi Howard.
It looks like your ZSQL method is not getting the form data it needs. Like you mentioned, you could pass those parameters explicitly when you call the the ZSQL method, or you could pass the REQUEST object to the ZSQL method:
<dtml-call "zsql_method(companyname=companyname, companyphone=companyphone, etc to the 29th parameter)"> or <dtml-call "zsql_method(REQUEST)"> Hey, you may want to try something like this - It might work and would not have to pass so much stuff to the ZSQL method: <dtml-call "zsql_method(form)">
I'm guessing it's more efficient to pass just the parameters the ZSQL method will need, but it is a pain to pass all 29 of them!
I hope that helps,
Eric.
Howard Hansen wrote:
I'm certain that I'm doing something very silly here, and I've learned many new things about Zope and databases by researching this problem, but I haven't figured out how to make it work.
All I want to do is create forms that allow me to insert or update records in a database.
Here's the structure I've set up:
form: collects the form data, and when the user clicks submit, it calls: action_dtml_method: which calls: zsql_method, which modifies the database and tells the user what just happened
When I hit Submit, I can easily list the values from the form inside the action_dtml_method, but zsql_method acts like it has no clue about the form values. It gives me the error:
Missing input variable, field_companyname
[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
[Howard Hansen]
I'm certain that I'm doing something very silly here, and I've learned many new things about Zope and databases by researching this problem, but I haven't figured out how to make it work.
All I want to do is create forms that allow me to insert or update records in a database.
Here's the structure I've set up:
form: collects the form data, and when the user clicks submit, it calls: action_dtml_method: which calls: zsql_method, which modifies the database and tells the user what just happened
When I hit Submit, I can easily list the values from the form inside the action_dtml_method, but zsql_method acts like it has no clue about the form values. It gives me the error:
Missing input variable, field_companyname
You have to do two things: 1) Declare the names of the parameters to plan to pass to the zsql method. You do this in the Management Interface page where you define the zsql method. 2) Use those parameters in your select statement, which is in the body of the zsql method. For example, if you have a form variable named "car_id", and you have declared it as a property in the zsql form, then you could write select * from cars where car=&dtml-car_id; (Or you can use <dtml-var car_id> instead) If this is not enough information, write again asking more specific questions. Cheers, Tom P
Howard Hansen writes:
Here's the structure I've set up:
form: collects the form data, and when the user clicks submit, it calls: action_dtml_method: which calls: zsql_method, which modifies the database and tells the user what just happened
When I hit Submit, I can easily list the values from the form inside the action_dtml_method, but zsql_method acts like it has no clue about the form values. It gives me the error:
Missing input variable, field_companyname Are you sure, the request contains "field_companyname"?
Dieter
participants (4)
-
Dieter Maurer -
Eric Walstad -
Howard Hansen -
Thomas B. Passin