On Sat, Dec 11, 2010 at 7:48 AM, gazza <[email protected]> wrote:
> I was thinking of just putting the error message in the session and
> let the controller deal with this but I think that kind of defeats the
> purpose?
>
> On Dec 10, 5:17 pm, gazza <[email protected]> wrote:
>>
>> I have written a fancy validator and its task is to verify whether
>> dates are within a valid a range.
>> However when it fails as expected I call:
>>
>> raise formencode.Invalid(msg,field_dict,state,
>>                                         error_dict=dict(orderid=msg))
>>
>> This simply renders the message to the browser as expected. Ideally I
>> want to reissue the page that
>> posted the date. Is there a way to do this using a fancy validator?
>>

Hello,

If you read through the tutorial on forms on the Pylons website
http://wiki.pylonshq.com/display/pylonsdocs/Form+Handling you'll note
under "The Quick Way" that they use a @validate decorator on the
methods that accept the form input.

What's happening behind the scenes in that validator is that it tries
to validate the form against the validator you specify. If it throws
the Invalid exception, then it renders the form presentation method
and populates the error messages and default values based on what was
submitted.

I don't know what you're do with the Invalid exception, but it sounds
like you are just trying to validate a value and not catching the
Invalid exception. It sounds like you'd like to know how to set
defaults and error messages for invalid submissions. If you study the
@validate decorator, you'll get some hints.

Of course, you can always do it the hard way. I have found a few use
cases where using formencode was more bother than not.

-- 
Jonathan Gardner
[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to