[Zope-DB] Results of a selection list

Charlie Clark charlie at begeistert.org
Tue Aug 12 17:56:36 EDT 2003

On 2003-08-12 at 16:17:06 [+0200], Andreas Tille wrote:
> Hi,
> I have a search form in which I want the user input some strings (in the 
> example only one to make it short) and a selection list like this:
> <form action="report" method="get">
> item: <input name="item"          width=20 value=""> <select name=select>
> <option tal:repeat="result here/selectSQL" tal:attributes="value 
> result/id" tal:content="result/name">
> </select>
> </form>
> The report method calls another Z SQL method.  Now I'm looking for a clue 
> how to ask for the select property only if an item is really selected. If 
> the user did not touched the list (or switched back to the first item of 
> the list) this property should be ignored.

As long as nothing has been selected then the form should contain no values 
for "select". What you might like to do is add a single option with no 
value to your select and make this "selected". You can then easily check 
the request.form to see whether you have a value from the form but you 
should be aware that different browsers do different things with forms: 
some will send empty name/value pairs and others will simply not send 
name/values for empty values. You can pepper your form with Javascript 
"onChange" or "onClick" but that's not something I would recommend.

Your PythonScript might look like the following:

required = ["item", "select"] # always a good idea to check for required 

for item, value in request.form.items():
	if value != "":

This script will only process non-empty name/value pairs in the form.


More information about the Zope-DB mailing list