[Zope-DB] multiple data insert (MySQL, Zope)
Charlie Clark
charlie@begeistert.org
Sun, 27 Oct 2002 11:44:31 +0000
Hi Fer=F3,
> <tr><td>Language(s): </td>
> <td><select name=3D"lang_id" size=3D4 multiple>
> <option value=3D"2">English
> </option><select name=3D"lang_id" size=3D4 multiple>
> <option value=3D"1">Hungarian
> </option><select name=3D"lang_id" size=3D4 multiple>
> <option value=3D"3">German
> </option><select name=3D"lang_id" size=3D4 multiple>
> <option value=3D"5">Italian
> </option><select name=3D"lang_id" size=3D4 multiple>
> <option value=3D"4">Russian
> </option></select></td></tr>).
If a an HTML-form has several entries for the same name, Zope will
automatically collect them as a list.
So your REQUEST object will have something like lang_id =3D ['1', '2']
This will definitely give you a type error when trying to insert in SQL!
I don't think SQL has support for multiple inserts so what you probably hav=
e
to do is process the form in a script and loop through list elements and ca=
ll
the appropriate ZSQL.
Something like
for item, value in REQUEST.form:
=09if item =3D=3D same_type[]: # a built-in for Zope
=09=09# we have list and need to loop through it
for v in value:
=09=09=09container.myZSQLMethod(item:v)
=09# we don't have a list
=09container.myZSQLMethod(item:value)
You can force the form to always produce a list by adding ":list" to the fo=
rm
element name, ie. <select name=3D"id_lang:list"><option
value=3D"1">English</option></select>
Note your original HTML is incorrect: you do not need to respecify "select"=
within an option.
I would advise you to move away from DTML for doing the form and onto ZPT.
And use PythonScripts for any kind of logic other than presentation.
Charlie
--
Charlie Clark
Helmholtzstr. 20
D=1Asseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226