On Wednesday 15 July 2009 10:56:44 Seth wrote: > Hey guys, > > So I've been messing around with tw.forms a little bit and maybe I'm > looking in the wrong places but I'm having a little bit of trouble > finding docs on some of the more advanced use cases. > > The biggest thing I'm trying to figure out is how to return to the > form after some custom validation in my "save" method. So I've got my > "form" method that loads a template with the form and submits to the > "save" method. I've got my @validate decorator on the "save" method > which works great and goes back to the "form" method if any of the > tw.form validators throw an error. All of that is working splendidly. > > However, I have some additional value-checking in the "save" method, > and want to redirect them back to the "form" method and use tg.flash() > to show something like "credit card declined". The bummer is that I > can't figure out how to make the form *keep the input* they've already > submitted. A redirect loses everything (tg.redirect converts POST to > GET), and forces the user to re-input all form data. Having the "save" > method 'return self.form(**kw)' doesn't seem to load the template from > the "form" method. Also, I don't really want to make the 'save' method > load a template because that's not its purpose. > > Please help shine some light on the subject for me. Any documentation > links for more advanced tw.forms topics/examples would also be > helpful.
Two answers to this: 1) whatever you do to validate, do it in validators. That's the way we currently go, and I don't see a reason not to do it. It's the clean road. 2) if you insist on doing it your way, I can only guess, but after a peek into tg.controllers it appears as raising a formencode.Invalid-exception from your controller *might* actually do what you want. Did you try that? If you are successful with the second approach, it would be good if you could come back here to tell us about that, so we know for future reference. Diez --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" 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/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

