Hi, all. I have a ZSQL insert function that requires an optional parameter. The variables are coming from an HTML form, and one of the variables is a checkbox. Apparently, if the checkbox is unchecked, the variable doesn't appear. As a small example, let's say there were two strings and a checkbox, labelled str1, str2 and cb. I need this: insert into mytable(col1, col2, col3) values (str1, str2, cb) as well as insert into mytable(col1, col2) values (str1, str2) if cb is None. I can't find any examples of optional insert variables, just optional join parameters. Also - is there a comprehensive ZSQL document anywhere? Thanks! -- Colin Fox cfox@crystalcherry.com CF Consulting Inc. GPG Fingerprint: D8F0 84E7 E7CC 5C6C 9982 F1A7 A3EB 6EA3 BC97 572F
On Wed, Mar 27, 2002 at 01:30:23PM -0800, Colin Fox mailed:
Hi, all.
I have a ZSQL insert function that requires an optional parameter.
The variables are coming from an HTML form, and one of the variables is a checkbox. Apparently, if the checkbox is unchecked, the variable doesn't appear.
As a small example, let's say there were two strings and a checkbox, labelled str1, str2 and cb. I need this:
insert into mytable(col1, col2, col3) values (str1, str2, cb)
as well as
insert into mytable(col1, col2) values (str1, str2)
if cb is None.
I can't find any examples of optional insert variables, just optional join parameters.
You could do something like this <dtml-if "REQUEST.has_attr(cb)"> <dtml-call dbInsert(str1 = REQUEST[str1], str2 = REQUEST[str2], cb = REQUEST[cb] )"> <dtml-else> <dtml-call dbInsert(str1 = REQUEST[str1], str2 = REQUEST[str2], cb = '' )"> </dtml-if> -- Bryan C. Andregg Duke University Medical Center Programmer Dept. of Anesthesiology e <bryan.andregg@duke.edu> p +1 919 684 6201
There is a trick for passing default values from forms in this case using marshaling: <input type="checkbox" name="foo" value="somevalue" /> <input type="hidden" name="foo:default" value="somedefault" /> The latter line uses a zope marshaling trick. If ZPublisher sees no other value for "foo" besides the default one it uses the default value from the hidden field. Otherwise it uses the value from the checkbox. hth, Casey Colin Fox wrote:
Hi, all.
I have a ZSQL insert function that requires an optional parameter.
The variables are coming from an HTML form, and one of the variables is a checkbox. Apparently, if the checkbox is unchecked, the variable doesn't appear.
As a small example, let's say there were two strings and a checkbox, labelled str1, str2 and cb. I need this:
insert into mytable(col1, col2, col3) values (str1, str2, cb)
as well as
insert into mytable(col1, col2) values (str1, str2)
if cb is None.
I can't find any examples of optional insert variables, just optional join parameters.
Also - is there a comprehensive ZSQL document anywhere?
Thanks!
I have a ZSQL insert function that requires an optional parameter.
The variables are coming from an HTML form, and one of the variables is a checkbox. Apparently, if the checkbox is unchecked, the variable doesn't appear.
That's correct. A rather unfortunate feature of HTML. Personally, I validate all HTML form input in a Python Script anyway. So it's easy to use Python to check for form variable existence, and provide a value for ZSQL method - because the ZSQL method is called by the Python Script.
Also - is there a comprehensive ZSQL document anywhere?
I'm afraid that Zope Book is the best resource existing. You can download Zope Book at http://www.zope.org free of charge. -- Milos Prudek
participants (4)
-
Bryan C. Andregg -
Casey Duncan -
Colin Fox -
Milos Prudek