[Zope] question about forms and zsql
Thomas B. Passin
tpassin@mitretek.org
Tue, 12 Feb 2002 12:02:50 -0500
[Tim Wilson]
> On Tue, 12 Feb 2002, Robert Hood, Ph.D. wrote:
>
> > In sql you can use LIKE %name% to let people search more flexibly.
> >
> > So how do I pass the %name% from the form to the method? Do I make the
> > change to the form, or to the zsql method?
>
> You might find my How-To "Combining ZSQL Methods With Python Scripts"
> helpful. It's at
> http://www.zope.org/Members/TWilson/ZSQL_and_Python_Scripts
>
> I think you'll find that a little Python Script is the way to go when
> you want to start splitting the form input and searching for matches.
>
You don't need to go to a python script. Instead, include a input element
in your form to hold the search phrase. Say you name that input field
"searchphrase". Then in your zsql method, you write something like
select * from table where name like '%&dtml-searchphrase;%'
Instead of the entity syntax, you could substitute <dtml-var
"REQUEST.searchphrase">,
or just <dtml-var searchphrase>
Just make sure to add searchphrase to the list of parameters for the zsql
method.
Finally, if the searchphrase value might have quotes in it, make sure to
use the sql quoting option (check the docs for the exact syntax).
Cheers,
Tom P