Kapil wrote:

Thanks, Kapil. I did look at dtml-contract, and it wasn't hard to 
understand it from the docs. But the problem is that it can't cover 
all the required tests - like dependencies between several form 
fields (such as with two password fields) or tests outside the form 
content (such as ensuring that a new product doesn't have an SKU that 
already exists, or that a user does not register with an existing 
email address). So a specific validation is required anyway. Also, 
all my form action is done in methods of Python Products where 
dtml-contract is not usable.


>On Tuesday 27 March 2001 17:40, Itai Tavor wrote:
>>>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
>>>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)?
>check out dtml-contract.
>sample form processor with dtml contract
>this page retrieves records from the db based on user input
>foobar:range(int, 0,10)
>user gets redirected if bar is not a valid date string, and foobar is not a
>integer compatible string between 0 and 10. if foo is present it must be a
>integer compatible string (compatible means coercible via int(foo)). if any
>of these things does not happen than all the collected errors for the page
>are sent to the error handler bad_user_input. this is not a redirect, the
>error handler is evaluated in the context of the page with an additonal value
>added to the namespace to denote the list of errors. page processing stops
>after evaluation of the tag if an error occurs.
>this may be clear as mud, i don't know, i tried to make the included
>documentation pretty inclusive and readable, its not completely insync with
>the code but it does elaborate on the feature set pretty well. if you have
>specific questions feel free to ask.
>so in your case you can just use the original form as the error handler and
>add logic to it to insert the values if they already exist in the request,
>and display error messages to the user on the particular vars that have
>problems based on the existence of the special error variable.
>>>TIA, Itai

Itai Tavor                      -- "Je sautille, donc je suis."    --
[EMAIL PROTECTED]            --               - Kermit the Frog --
--                                                                 --
-- "If you haven't got your health, you haven't got anything"      --

Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to