From: Matt F. <ma...@da...> - 2003-09-19 19:44:41
|
Aaron Held wrote: > >> I'm still not very clear on the "recommended" way to create >> forms in awake(), since the way I'm doing it, by manipulating >> self._forms, doesn't seem very natural. If this is the right >> way, I can create an example for your Examples folder. If >> not, and you find the time before the next release, an example >> of a form created in awake() would be helpful, I think. :) >> >> Thanks! > > > Not sure if I am doing it the "correct way" but I have a page where > the form is generated on the fly each time. We had a pretty serious goal when designing FormKit for there not to be a "correct" way. The MixIn is good for beginners to get started, but we wanted the form mechanics to be useful without that. We even use FK without servlets now and then... basically, it's just an html tag builder and value parser... much ado about nothing. > Then if the user send forminfo I do: > > def showReport(self) > self.initForm() > fields = self.request().fields() > self.form1.process( fields ) > # save the user values > currentValues = {} > for f in self.form1.fields(): > currentValues[f.name()] = f.value() The self.form1.values() method does what those last two lines do ;-) > formValid = self.form1.isSuccessful() > if not formValid: > f1 = self.form1 > put back the user values > f1.seed(currentValues) > self.writeForm('Error') > else: > self.writeReportHTML() > You shouldn't have to seed the form; the values should still be in there, after they were processed. Unless you call a .reset() or something, the inputs are still there (as are the defaults, if any). > This has the disadvantage of building up the form class each run. > You may want to use some instance caching in initForm to save the form > between runs, and then call something to .sleep each form in > servlet.sleep. You can certainly do that, but it shouldn't be too much overhead; FK is basically just making strings. |