[Zope] Checkboxes/SQL data type problem
Dieter Maurer
dieter@handshake.de
Thu, 20 Jun 2002 20:23:27 +0200
Aseem Mohanty writes:
> when you use checkboxes with the same name or for that matter similar
> names <input name="..."> in a form, the item in the REQUEST variable is
> a list or in case of Zope a list-string of the form "['a','b','c']".
> Write a python script to convert it to a list.
Please do not follow this advice!
You will make your life much more difficult than necessary.
First of all:
If you have checkboxes with the same name, you will get:
1. no value for the name at all, when no checkbox is checked
2. a single string value with the checkbox "value", when a single checkbox
if checked
3. a list of the checked checkbox values, when more than 1 checkbox is checked
It is very nasty to handle these different types of behaviour.
Fortunately, there is Zope (more precisely: ZPublisher) magic, to get
a uniform behaviour:
When you add ":list" to the name, you will always get a list when you
get anything at all. This will unify cases 2 and 3 above.
When you add an addition hidden variable with your basename
suffixed with ":tokens:default" and an empty value, then you
will get an empty list for the first case. This unifies
case 1.
Together, you will always get a list representing precisely
the checked checkboxes.
The hints above apply in the same way to multiple sections and
lists coded as sequences of hidden variables in an HTML form.
Read more about it on
<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
Dieter