Zope
  Home arrow Zope arrow Page 8 - ZPT Basics (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ZOPE

ZPT Basics (part 2)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 13
    2002-09-25


    Table of Contents:
  • ZPT Basics (part 2)
  • A Little Male Bonding
  • The Number Game
  • A Question Of Scope
  • Switching Things Around
  • Comparing Apples and Oranges
  • If It's Thursday, It Must be Italy
  • Submitting To The King
  • Looking Ahead

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    ZPT Basics (part 2) - Submitting To The King
    ( Page 8 of 9 )

    You may remember, from the first part of this series, an example involving a form and a form processor. In that example, I used two Zope objects - a single DTML Document to display the form, and a separate page template to process the form input and generate appropriate output. However, ZPT provides an elegant method to combine those two pages into one via the "submit" variable.

    In order to better understand this, create a Page Template named "DualPurposeForm" and add the following code to it:
    <div tal:define="global submit request/form/submit | nothing" tal:condition="not:submit"> <form action="DualPurposeForm" method="POST"> Species: <br> <input name="species"> <p> Home planet: <br> <input name="planet"></p> <p> Distance (light years) from Earth: <br> <input name="distance"></p> <p> <input type="Submit" name="submit" value="Beam Me Up, Scotty"></p> </form> </div> <div tal:condition="submit"> <p>Welcome to Earth, <b tal:content="request/form/species">alien species name</b> from the planet <b tal:content="request/form/planet">planet name</b>. </p> <p>How was your journey? Travelling <b tal:content="request/form/distance">distance</b> light years must be quite a shock to the system. Why don't you relax and have a drink?</p> </div>
    There are two conditional tests in the template above, both keyed on the presence or absence of the "submit" variable. The first time the template is accessed, the "submit" variable will not exist, and therefore the first conditional test will evaluate to true and the form will be displayed. Once the form has been submitted, the same template will be called again. However, this time around, the "submit" variable will exist in the request context, and so the second part of the template will be displayed.

    There are a couple of things to note in the example above. First, the template variable "submit", which is set depending on the presence of a form "submit" variable in the request object. In case this variable does not exist, the template variable "submit" is set to the special value "nothing". You may remember, again from the first part of this series, that "nothing" is a special TAL variable used to represent a null value.

    Second, the usage of the "not" keyword in the first conditional test. This keyword evaluates the TALES expression that follows, and returns the Boolean reverse of the result. Thus, the first time the template is accessed, the value of the "submit" variable will be set to null, the TALES expression will evaluate to Boolean false and the "not" negation will convert it to Boolean true...which serves as a flag to display the empty form.

    This technique makes it possible to reduce the number of objects used, and perhaps make your Zope object collection easier to handle.

     
     
    >>> More Zope Articles          >>> More By Harish Kamath, (c) Melonfire
     

       

    ZOPE ARTICLES

    - Creating Zope Products
    - Plone Content Types With Archetypes
    - Flat User Management in Zope
    - Creating Basic Zope Applications
    - Getting started with Zope for Linux and Sola...
    - ZPT Basics (part 4)
    - ZPT Basics (part 3)
    - ZPT Basics (part 2)
    - ZPT Basics (part 1)
    - Exception Handling In DTML
    - DTML Basics (part 4)
    - DTML Basics (part 3)
    - DTML Basics (part 2)
    - DTML Basics (part 1)
    - Using Zope With Apache





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek