Home arrow Zope arrow Page 8 - DTML Basics (part 2)

Submitting To The King - Zope

In this second article, dive a little deeper into theintricacies of DTML by getting up close and personal with conditionalstatements and comparison operators. This article discusses thedifferent variants of the "if" statement available in DTML, togetherwith examples and code listings that demonstrate how they can be used ina Web applications.

TABLE OF CONTENTS:
  1. DTML Basics (part 2)
  2. If Only...
  3. Comparing Apples And Oranges
  4. Welcome To The Matrix
  5. Celluloid Dreams
  6. Paring It Down
  7. Deeper And Deeper
  8. Submitting To The King
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 4
June 05, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
You'll have noticed that in all the examples shown thus far, we've usedtwo Zope objects - a single DTML Document containing the form, and aseparate DTML Method which processes the form input and generatesappropriate output. However, DTML provides an elegant method to combinethose two pages into one via the "submit" variable.

In order to better understand this, create a new DTML Document named"DualPurposeForm" and add the following DTML code to it:

<dtml-var standard_html_header>

<dtml-if submit>

Welcome to Earth, <b><dtml-var species missing="Alien"></b> from the
planet <b><dtml-var planet missing="Zorgo"></b>.
<p>
How was your journey? Travelling <b><dtml-var distance missing="so
many"></b> light years must be quite a shock to the system. Why don't
you relax and have a drink?

<dtml-else submit>

<form action="DualPurposeForm" method="POST">
Species:
<br>
<input name="species">
<p>
Home planet:
<br>
<input name="planet">
<p>
Distance (light years) from Earth:
<br>
<input name="distance">
<p>
<input type="Submit" name="submit" value="Beam Me Up, Scotty"> </form>

</dtml-if>

<dtml-var standard_html_footer>
In this case, the DTML "if" test will first check to see if the "submit"form variable exists. If it does, it implies that the form has beensubmitted, and the second half of the script, the actual form processor,comes into play. If it doesn't, it implies that the form has not yetbeen submitted, and so the initial, empty form is displayed.

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

And that's about it for the moment. In this article, you learnt a littlemore about DTML, specifically about how to introduce decision-makinglogic into your Methods with DTML's numerous conditional statements. Youlearnt about the "if" and "unless" series of conditional statements, andsaw a few examples of the different variants possible. Finally, you sawhow all that theory can be put to practical use by implementing a simpleform processor for use on a Web page.

In the next issue of DTML Basics, I'll be rounding out the fundamentalswith a look at the various loop constructs provided by DTML. As witheverything you've seen so far, DTML comes with its own twist (pardon thepun) on the traditional way of implementing loops. Come back next timeto see what I'm talking about...and, until then, go practise.

Note: All examples in this article have been tested on Linux/i586 withZope 2.5.0. Examples are illustrative only, and are not meant for aproduction environment. Melonfire provides no warranties or support forthe source code described in this article. YMMV!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

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

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: