FrontPage
»
GetAndPostToSamePage
»
GetAndPostExampleOne
I think this embodies some ideas from GetAndPostToSamePage. I started from the smart form HOWTO. This is condensed to dodge structured text formatting. You can see the real-life version at http://www.sonoma-systems.com/resources/wine.htm .
<dtml-call "REQUEST.set(need_fullname
,'')"> <dtml-call "REQUEST.set(need_email
,'')"> <dtml-if "REQUEST.REQUEST_METHOD=='POST'"> <dtml-comment> If we're here, the user has hit the submit button and we have form data to consider. Validate all fields and either process the form or redisplay it. </dtml-comment> <dtml-call "REQUEST.set(finished
,true
)"> <dtml-unless "fullname"> <dtml-call "REQUEST.set(finished
,false
)"> <dtml-call "REQUEST.set(need_fullname
,<b><--</b><i> required</i>
)"> </dtml-unless> <dtml-if "not email"> <dtml-call "REQUEST.set(finished
,false
)"> <dtml-call "REQUEST.set(need_email
,<b><--</b><i> required</i>
)"> <dtml-else> <dtml-call "REQUEST.set(e1
,_.string.split(email,@
))"> <dtml-call "REQUEST.set(e2
,_.string.split(e1[-1],.
))"> <dtml-unless " _.len(e1) == 2 and _.len(e1[0]) > 0 and _.len(e2) >= 2 and _.len(e2[0]) > 0 and _.len(e2[1]) > 0 "> <dtml-call "REQUEST.set(finished
,false
)"> <dtml-call "REQUEST.set(need_email
,<b><--</b><i> invalid email address ?</i>
)"> </dtml-unless> </dtml-if> <dtml-if "REQUEST.finished == 'true'"> <dtml-comment> we have all the data we need - process the form </dtml-comment> <dtml-var form_done> <dtml-else> <dtml-comment> invalid data - redisplay the form </dtml-comment> <strong>Please address the problems indicated below:</strong> <dtml-var form_form> </dtml-if> <dtml-else> <dtml-comment> no form data - display the form for the first time </dtml-comment> <dtml-var form_hdr> <dtml-var form_form> </dtml-if>
form_hdr contains introductory content
form_form contains the actual form, something like this:
<form id="exampleform" action="exampleform" method="post"> <label for="fullname"><b>Full Name:</b></label> <input type="text" id="fullname" name="fullname" value="&dtml.missing-fullname;" size="30" maxlength="60" tabindex=1> <font color="red"><dtml-var need_fullname></font> <br> <label for="email"><b>Email:</b></label> <input type="text" id="email" name="email" value="&dtml.missing-email;" size="30" maxlength="60" tabindex=2> <font color="red"><dtml-var need_email></font> <br> ...
and form_done does the action and displays acknowledgement content. When managing a zope object you would redisplay the form along with the acknowledgement.