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

 
Developer Updates  
Free Website Content 
eWeek
 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? 
ZOPE

ZPT Basics (part 2)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

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

    You may remember, from the first part of this series, an exampleinvolving a form and a form processor. In that example, I used two Zopeobjects - a single DTML Document to display the form, and a separatepage template to process the form input and generate appropriate output.However, ZPT provides an elegant method to combine those two pages intoone 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 speciesname</b> from the planet <b tal:content="request/form/planet">planetname</b>. </p><p>How was your journey?Travelling <b tal:content="request/form/distance">distance</b> lightyears 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 thepresence or absence of the "submit" variable. The first time thetemplate is accessed, the "submit" variable will not exist, andtherefore the first conditional test will evaluate to true and the formwill be displayed. Once the form has been submitted, the same templatewill be called again. However, this time around, the "submit" variablewill exist in the request context, and so the second part of thetemplate will be displayed.

    There are a couple of things to note in the example above. First, thetemplate variable "submit", which is set depending on the presence of aform "submit" variable in the request object. In case this variable doesnot 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 returnsthe Boolean reverse of the result. Thus, the first time the template isaccessed, the value of the "submit" variable will be set to null, theTALES expression will evaluate to Boolean false and the "not" negationwill convert it to Boolean true...which serves as a flag to display theempty 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-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway