[Zope] Handling results from <select> tag

Alexander Staubo alex@mop.no
Thu, 6 May 1999 22:49:17 +0200


Consider a form:

  <form action="Post">
    <select name="Values" multiple>
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
   </select>
   ...

I have the request handling stuff working 100%, except for the case when
the user selects only a single value. This seems to be because Zope
converts result values to a list. So, if the user selects multiple
values, form.Values becomes a list, like:

  ['A', 'B', 'C']

But if the user selects a single value, form.Values becomes a single
value, like

  'A'

How do I effectively and foolproofly handle this sort of case?

Although the solution ought to be indepedent of my specific code, I
ought to explain a bit. Basically, my code aims to join two lists: one
gotten from a <select>, the other from a simple <input>. It looks like
this:

  <!-- first, convert from a list into a simple string, delimited with
"," -->
  <!--#call "REQUEST.set('select', _.string.join(select, ','))"-->
  <!-- then join the two strings into a list based on the assumed
delimiter -->
  <!--#call "REQUEST.set('values, _.string.join(_.string.split(select +
input, ','), ','))"-->

Yeah, not very pretty. Anyway, if select is ['A', 'B'] and input is 'C,
D', the resulting string should because 'A', 'B', 'C', 'D'. Easy as pie,
and it works fine, except if select isn't a list.

In Python, you can simply check the type of variable:

  if type(select) == type([]): ...

But this won't work in Zope.

Any suggestions?

Alexander Staubo
http://www.mop.no/~alex/
mailto:redhand@mop.no