Home arrow Zope arrow Page 5 - Form Processing With Zope

In The Raw - Zope

Ever wondered how to create and process HTML forms in the Zope environment? Relax. It's simpler than you think.

TABLE OF CONTENTS:
  1. Form Processing With Zope
  2. Driving Under The Influence
  3. Stringing Things Along
  4. Running On Empty
  5. In The Raw
  6. You've Got Mail!
  7. Endgame
By: Team Melonfire, (c) Melonfire
Rating: starstarstarstarstar / 13
February 26, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
In case you want to see what values are being passed back and forth between the Form and FormProcessor, you can simply display the contents of the REQUEST namespace. Take a look at the form processor below for an understanding of what this means:

<dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer>
Now, when you submit a form to this FormProcessor object, you'll see something like this:



The REQUEST namespace contains a whole bunch of environment and Zope variables that you can use for your own dark purposes. These include, among others, the standard variables HTTP_USER_AGENT, HTTP_REFERER and PATH_INFO, Zope-specific variables like PUBLISHED, SERVER_URL, AUTHENTICATED_USER and URL0, and cookie and session data.

This ability to access form variables in this manner brings up another interesting item. Thus far, I've been creating individual Form and FormProcessor objects. However, it's also possible to create a combined object, simply by testing for the presence or absence of 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:ignore-empty"> <p> Home planet: <br> <input name="planet:ignore-empty"> <p> Distance (light years) from Earth: <br> <input name="distance:ignore-empty"> <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 been submitted, 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 yet been 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.

There are a couple of other things you could do to the form object above. First, you could replace the object name in the form's ACTION attribute

<form action="DualPurposeForm" method="POST">
with the special Zope variable "URL0".

<form action=<dtml-var URL0> method="POST">
URL0 is a Zope variable which always holds the name of the current URL (you'll see it in the list of variables displayed within the REQUEST namespace). Using this built-in variable covers you in case you need to change the object name in future. You might also want to wrap the "if" test within a namespace localizer - for example, <dtml-with> - in order to ensure that Zope checks the REQUEST namespace for the "submit" variable first, rather than any other namespace that exist.

 
 
>>> More Zope Articles          >>> More By Team Melonfire, (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: