You are not logged in Log in Join
You are here: Home » Members » jim » ZopeSecurity » GetAndPostExampleOne

Log in
Name

Password

 
 

History for GetAndPostExampleOne

??changed:
-
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 .

<pre>
&lt;dtml-call "REQUEST.set('need_fullname','')"&gt;
&lt;dtml-call "REQUEST.set('need_email','')"&gt;
&lt;dtml-if "REQUEST.REQUEST_METHOD=='POST'"&gt;
  &lt;dtml-comment&gt;
  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.
  &lt;/dtml-comment&gt;
  &lt;dtml-call "REQUEST.set('finished','true')"&gt;
  &lt;dtml-unless "fullname"&gt;
    &lt;dtml-call "REQUEST.set('finished','false')"&gt;
    &lt;dtml-call "REQUEST.set('need_fullname','&lt;b&gt;&lt;--&lt;/b&gt;&lt;i&gt; required&lt;/i&gt;')"&gt;
  &lt;/dtml-unless&gt;
  &lt;dtml-if "not email"&gt;
    &lt;dtml-call "REQUEST.set('finished','false')"&gt;
    &lt;dtml-call "REQUEST.set('need_email','&lt;b&gt;&lt;--&lt;/b&gt;&lt;i&gt; required&lt;/i&gt;')"&gt;
  &lt;dtml-else&gt;
    &lt;dtml-call "REQUEST.set('e1',_.string.split(email,'@'))"&gt;
    &lt;dtml-call "REQUEST.set('e2',_.string.split(e1[-1],'.'))"&gt;
    &lt;dtml-unless "
                  _.len(e1) == 2 and 
                  _.len(e1[0]) &gt; 0 and 
                  _.len(e2) &gt;= 2 and
                  _.len(e2[0]) &gt; 0 and 
                  _.len(e2[1]) &gt; 0
                 "&gt;
      &lt;dtml-call "REQUEST.set('finished','false')"&gt;
      &lt;dtml-call "REQUEST.set('need_email','&lt;b&gt;&lt;--&lt;/b&gt;&lt;i&gt; invalid email address ?&lt;/i&gt;')"&gt;
    &lt;/dtml-unless&gt;
  &lt;/dtml-if&gt;
  &lt;dtml-if "REQUEST.finished == 'true'"&gt;
    &lt;dtml-comment&gt;
    we have all the data we need - process the form
    &lt;/dtml-comment&gt;  
    &lt;dtml-var form_done&gt;
  &lt;dtml-else&gt;
    &lt;dtml-comment&gt;
    invalid data - redisplay the form
    &lt;/dtml-comment&gt;
    &lt;strong&gt;Please address the problems indicated below:&lt;/strong&gt;
    &lt;dtml-var form_form&gt;
  &lt;/dtml-if&gt;
&lt;dtml-else&gt;
  &lt;dtml-comment&gt;
  no form data - display the form for the first time
  &lt;/dtml-comment&gt;
  &lt;dtml-var form_hdr&gt;
  &lt;dtml-var form_form&gt;
&lt;/dtml-if&gt;
</pre>

*form_hdr* contains introductory content

*form_form* contains the actual form, something like this:

<pre>
&lt;form id="exampleform" action="exampleform" method="post"&gt;
&lt;label for="fullname"&gt;&lt;b&gt;Full Name:&lt;/b&gt;&lt;/label&gt;
&lt;input type="text" id="fullname" name="fullname" value="&dtml.missing-fullname;" size="30" maxlength="60" tabindex=1&gt;
&lt;font color="red"&gt;&lt;dtml-var need_fullname&gt;&lt;/font&gt;
&lt;br&gt;
&lt;label for="email"&gt;&lt;b&gt;Email:&lt;/b&gt;&lt;/label&gt;
&lt;input type="text" id="email" name="email" value="&dtml.missing-email;" size="30" maxlength="60" tabindex=2&gt; 
&lt;font color="red"&gt;&lt;dtml-var need_email&gt;&lt;/font&gt;
&lt;br&gt;
...
</pre>

and *form_done* does the action and displays acknowledgement content. When managing a zope object you would redisplay the form along with the acknowledgement.