[Zope-dev] ZPatterns, DataSkins, forms and error checking/handling
Itai Tavor
itai@optusnet.com.au
Wed, 28 Mar 2001 11:40:35 +1000
Hi,
I'm trying to work out the best way to check for and report errors
when DataSkin objects are created/edited, but I'm having a lot of
problems.
For form validation, Zope's build-in constraints are pretty
useless... things like ValueHandler are a little better, but IMO not
good enough. When a user types incorrect data in a form, I don't want
to display a page with a list of errors and say "click Back to fix
your errors". I want to return the form, with a list of errors and
the bad fields highlighted. So I need to perform field checks in the
form action method and in case of errors call the original form,
giving it an error list.
I know that to ensure that object data is always valid I should
validate the object in a SkinScript, using WHEN OBJECT ADDED,CHANGED
call self.validate(), and raise an exception in validate in case of a
problem. But this can't deal with returning the original form. It can
only display error pages, and to display nicely formatted error pages
it has to return a DTML Method so I can use dtml-raise, rather than
directly do raise in validate.
So I'm looking at a validate method for use at commit time, a
show_errors DTML Method, and a validate_form to call from the form
action method...
The validate_form method is defined in the DataSkin class. But it is
also used when a new object is created from a form, so it needs to be
called from a Specialist before the object is created, so I need to
import it in the Specialist. But this method might use other methods
of the DataSkin class, so I need to import those too...
So, to sum up, I need a method used in commit time, that renders a
DTML method to raise an error message, another method to verify form
submissions and return the form with error messages, and I need to
import that method and all other methods it uses into the Specialist.
This seems too much work...
Can anyone suggest a simpler approach (one that still retains the
ability to return the original form in case of errors)?
TIA, Itai
--
--
Itai Tavor -- "Je sautille, donc je suis." --
itai@optusnet.com.au -- - Kermit the Frog --
-- --
-- "If you haven't got your health, you haven't got anything" --