I think I got it: I can use onvalidate and set the form.errors when the
exception is tripped. That way, the form is never successfully submitted.
Although now I have the problem where the form errors are displayed twice
for fields that have their own validate function set.
For example, setting the "requires=IS_INT_IN_RANGE(1,100)" for an INPUT()
will show up twice. Once underneath the input tag, and again in the html
where I set {{=BEAUTIFY(form.errors)}}
How would I disable the error display underneath the input tag?
On Wednesday, January 23, 2013 10:16:57 PM UTC-5, Ragtime AllTime wrote:
>
> I think I may be going about this wrong, but I want to throw new form
> errors if something happens after doing form.accepts(...). I'm not using
> SQLFORM or CRUD, just the FORM().
>
> The scenario is something like this: The user enters payment information
> correctly, but when I charge the card, the card is returned declined. Then,
> the form should display an error saying that there are errors with the card
> and present the user with the form again, as though validation had failed.
> The same flow would go with emailing the user too.
>
>
> form = FORM(...)
>
> if form.accepts(request, session):
> try:
> makePayment(....)
> redirect(URL('successful_payment')) # Redirect after success
> except ...
> # Display Errors on form here and show the form to the user.
>
> elif form.errors: # Validation has failed
> response.flash = 'form has errors'
>
>
>
> What would go in the except block?
>
--