Hi-- I'm finding the example of the form/action/response pattern in Chapter 9 of the Zope book a little opaque, because some of the pieces are missing and (as a newbie) I don't know which ones. Can anyone point me to a complete worked example? From the request form, through the scripted action, to the response. I'll take care of getting it into the book, if someone will post it here. (No DTML please -- I want ZPT!) Sam Hunting eTopicality, Inc. --------------------------------------------------------------------------- "Turn your searching experience into a finding experience."(tm) Topic map consulting and training: www.etopicality.com Free open source topic map tools: www.gooseworks.org XML Topic Maps: Creating and Using Topic Maps for the Web. Addison-Wesley, ISBN 0-201-74960-2. ---------------------------------------------------------------------------
Sam Hunting wrote:
Can anyone point me to a complete worked example? From the request form, through the scripted action, to the response.
Here's a quick sample of the pattern I usually use. The Script controls the action: ## Script (Python) "formDemo" ##parameters=data=None ## form = container['formDemo.zpt'] if data is None: return form() errors = {} if not data.name.strip(): errors['name'] = 'Name is required' if data.ssn.strip(): if len(data.ssn.strip()) < 9: errors['ssn'] = 'SS # must be nine digits' else: errors['ssn'] = 'SS # is required' if errors: return form(errors=errors) # Do something with the valid data ...and the Page Template displays the form: <html> <body> <form method="POST" tal:attributes="action request/URL" tal:define="data request/form/data | nothing"> <div>Name: <input name="data.name:record" tal:attributes="value data/name | nothing" /> <span tal:replace="options/errors/name | nothing">Error</span> </div> <div>SS#: <input name="data.ssn:record" tal:attributes="value data/ssn | nothing" /> <span tal:replace="options/errors/ssn | nothing">Error</span> </div> <div><input type="submit" value="Submit" /></div> </form> </body> </html> Cheers, Evan @ 4-am
participants (2)
-
Evan Simpson -
Sam Hunting