Question involving passing optional parameters to a zsql method
I have a form with 7 checkboxes. The more checkboxes are selected the more narrow of results you will get. I created a zsql method that will handle every case as far as when to include 'AND','OR', and '()'. The problem now is getting my form to execute the zsql method correctly. When I hit the submit button the boxes that are not check will trigger an error message stating that the variable was not defined. I am trying to figure out when I hit the submit button my dtml method that runs the zsql method is not written to adjust for empty parameters. I had originally called my function like this: <dtml-call expr="findResults(location1=location1, location2=location2, ..., usetype1=usetype1, usetype2=usetype2,...,active=active)"> Does anyone have an idea on how to call this function regardless of what boxes are checked? thanks.
On Tue, 19 Oct 2004 10:19:50 -0500 "Laura McCord" <Laura.McCord@doucet-austin.com> wrote:
I have a form with 7 checkboxes. The more checkboxes are selected the more narrow of results you will get. I created a zsql method that will handle every case as far as when to include 'AND','OR', and '()'.
The problem now is getting my form to execute the zsql method correctly. When I hit the submit button the boxes that are not check will trigger an error message stating that the variable was not defined.
I am trying to figure out when I hit the submit button my dtml method that runs the zsql method is not written to adjust for empty parameters. I had originally called my function like this: <dtml-call expr="findResults(location1=location1, location2=location2, ..., usetype1=usetype1, usetype2=usetype2,...,active=active)">
Does anyone have an idea on how to call this function regardless of what boxes are checked?
Suppose you have checkbox with name 'foo'. In your DTML method, before your ZSQL call, do: <dtml-call "REQUEST.set('foo', REQUEST.has_key('foo'))> This will set the variable 'foo' to 0 if the checkbox name is not in the REQUEST (not checked), and 1 if the the checkbox name is in the request (checked). This is exactly what you want.
thanks. _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Am Di, den 19.10.2004 schrieb Jim Penny um 17:32:
On Tue, 19 Oct 2004 10:19:50 -0500 "Laura McCord" <Laura.McCord@doucet-austin.com> wrote: ... Suppose you have checkbox with name 'foo'. In your DTML method, before your ZSQL call, do:
<dtml-call "REQUEST.set('foo', REQUEST.has_key('foo'))>
This will set the variable 'foo' to 0 if the checkbox name is not in the REQUEST (not checked), and 1 if the the checkbox name is in the request (checked). This is exactly what you want.
Hm. I doubt that. This would actually set the variable to True or False. Solutions: REQUEST.get() can take a default value: foo=REQUEST.get('foo',0) which will return the actual value or 0 Also, ZSQL Methods DTML have default value modifiers - check Zope-Book for details. Of course it depends on what Laura is really doing here. Regards Tino
On Tue, 19 Oct 2004 18:51:27 +0200 Tino Wildenhain <tino@wildenhain.de> wrote:
Am Di, den 19.10.2004 schrieb Jim Penny um 17:32:
On Tue, 19 Oct 2004 10:19:50 -0500 "Laura McCord" <Laura.McCord@doucet-austin.com> wrote: ... Suppose you have checkbox with name 'foo'. In your DTML method, before your ZSQL call, do:
<dtml-call "REQUEST.set('foo', REQUEST.has_key('foo'))>
This will set the variable 'foo' to 0 if the checkbox name is not in the REQUEST (not checked), and 1 if the the checkbox name is in the request(checked). This is exactly what you want.
Hm. I doubt that. This would actually set the variable to True or False.
Try it. Of course, it depends on version on python. As I recall 2.2 and earlier did not have True or False as distinguished values. But the point is a bit moot, as the SQL adapter is still responsible for converting True/False to something usable by the SQL layer.
Solutions: REQUEST.get() can take a default value:
foo=REQUEST.get('foo',0)
which will return the actual value or 0
But, you hardly ever want the actual value! A checkbox creates a name in the REQUEST, along with a value. Unless you are very careful, the value will NOT be something that the SQL adapter can handle as a representation of true. Of course, you can write all your forms as <input type="checkbox" value="1" name="foo">, but what's the point? Jim Penny
Am Di, den 19.10.2004 schrieb Jim Penny um 19:08:
On Tue, 19 Oct 2004 18:51:27 +0200 Tino Wildenhain <tino@wildenhain.de> wrote: ... Try it. Of course, it depends on version on python. As I recall 2.2 and earlier did not have True or False as distinguished values. But the point is a bit moot, as the SQL adapter is still responsible for converting True/False to something usable by the SQL layer.
Yeah, but we are on python2.3 already ;)
Solutions: REQUEST.get() can take a default value:
foo=REQUEST.get('foo',0)
which will return the actual value or 0
But, you hardly ever want the actual value! A checkbox creates a name in the REQUEST, along with a value. Unless you are very careful, the value will NOT be something that the SQL adapter can handle as a representation of true. Of course, you can write all your forms as
<input type="checkbox" value="1" name="foo">, but what's the point?
Usually you have checkboxes with the same name and different values to not to have to fish in the request for arbitrary variable names. So its more like: <input type="checkbox" value="1" name="foo:int:list" /> <input type="checkbox" value="2" name="foo:int:list" /> <input type="checkbox" value="3" name="foo:int:list" /> and so on. which gives you foo as list with the values (all ints in the example) foo=request.get("foo",[]) handles the case when no checkbox has ben checked. However as I said, it depends on what Laura wants to do with the data, so one or the other method is more convient. Regards Tino
Laura McCord wrote:
I have a form with 7 checkboxes. The more checkboxes are selected the more narrow of results you will get. I created a zsql method that will handle every case as far as when to include 'AND','OR', and '()'.
The problem now is getting my form to execute the zsql method correctly. When I hit the submit button the boxes that are not check will trigger an error message stating that the variable was not defined.
That's "ok", nothing is submitted for checkboxes that are not checked, so ZPublisher does not add the name to the REQUEST, so the function call complains about undefined variables.
I am trying to figure out when I hit the submit button my dtml method that runs the zsql method is not written to adjust for empty parameters. I had originally called my function like this: <dtml-call expr="findResults(location1=location1, location2=location2, ..., usetype1=usetype1, usetype2=usetype2,...,active=active)">
Does anyone have an idea on how to call this function regardless of what boxes are checked?
provide default values for missing parameters (either in the function definition or in the form) or write the function in such a way that can handle missing parameters (perhaps testing REQUEST.has_key('check1')). HTH -- //// (@ @) ----------------------------oOO----(_)----OOo-------------------------- <> Ojo por ojo y el mundo acabara ciego /\ Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain) -----------------------------------------------------------------------
participants (4)
-
Alexis Roda -
Jim Penny -
Laura McCord -
Tino Wildenhain