[Zope-dev] Stumped about handling this particularexception...

Paulo Eduardo Neves neves@inf.puc-rio.br
Wed, 28 Apr 1999 20:55:25 -0300


Amos Latteier wrote:
> 
> At 10:19 PM 4/27/99 -0400, Skip Montanaro wrote:
> >
> >instead of a useful message that will help the user figure out what they did
> >wrong.  This makes them think my web site is broken, when it's actually
> >their input that's broken...
> 
> Yes. ZPublisher's type converters are quite primitive. They don't offer
> much control over how value are coerced and frustratingly they don't allow
> control over how errors are handled. Finally, there is no interface for
> extending the converters, i.e. it's hard to figure out how to add your own
> converters.
> 
...
> 
> In the short term I can recommend these avenues to solve your problem.
> 
>   * Don't use type converters and do all the form validation in your
> published object. This way you have total control. 

I've also tried to use the type converters were for input validation.
Today I usually use a external method for complex forms or dtml for the
simple ones. Although  it doesn't serve for input validation, I like to:
	1. Use :list to guarantee that a multiple selection input (checkbox or
	 multiple select) is returned as a list even if just one is selected
	2. :int for the cases where you specify the form value. It is very
	 common to use it with :list to have a list of integers. 
	3. :text in a textarea field to have a lot of newlines become just one
	 and to have consistent newlines in the text. 

I've also already used :lines. The problem of these converters is that
they aren't good even for marshaling. If you use :int or :float in a
text input form you have the chance to get the ugly error screen. Since
you don't have any way to control the output screen, it can crash the
usability of your site. It's better to use them in very specific
situations or in prototypes.

Another approach is to use javascript to validate it before submitting
it. A js library for this was posted sometime ago in the zope list. It
just guarantee that an invalid field won't be submitted if ALL your
users have javascript turned on.

regards,
--
Paulo Eduardo Neves
mailto:neves@inf.puc-rio.br
PUC-Rio de Janeiro