Form Processing With Zope (
Page 1 of 7 )
Ever wondered how to create and process HTML forms in the Zope environment? Relax.
It's simpler than you think.The thing about Zope is, everyone wants to use it, but most people don't know
where to start.
Take, for example, something as simple as building a feedback form. For a PHP
or Perl developer, this is a doddle, requiring no more than a couple hours of
development time (OK, OK, a little more if it requires complex validation or processing).
Building a feedback form in PHP or Perl is neither scary or intimidating; in fact,
it's one of the most fundamental things a Web developer needs to know to consider
himself even reasonably proficient in the language.
Put that same PHP or Perl developer on a Zope-based platform, however, and the
sweat will really start trickling. Zope's object-oriented approach to everything
tends to confuse even the most versatile PHP or Perl programmer, and you can expect
that one hour to telescope into a couple of days, as our fearless programmer struggles
to master the intricacies of Zope objects, variables and methods.
In case you ever find yourself in this situation, you're going to be glad you
found this article. Over the next few pages, I'm going to give you a broad overview
of the process of building and processing Zope forms, demonstrating how simple
and painless the process really is.
I'll be assuming that you know the basics of Zope - variables, and the like -
and that you have a Zope 2.50 system up and running. {mospagebreak title=Making
New Friends} We'll start with something simple, a form with three fields and a
form processor that displays the data entered into the form.
The first step is to create a couple of DTML Document objects (via the Zope Management
Interface, usually available at http://your_zope_server:8080/your_folder/manage)
to represent these two items. I've called them Form and FormProcessor respectively;
feel free to name them whatever you want.
First, let's look at the Form object:
<dtml-var standard_html_header>
<form action="FormProcessor" 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" value="Beam Me Up, Scotty">
</form>
<dtml-var standard_html_footer>
This isn't very hard to read, even if you've never worked with Zope before. It's
a standard HTML form, with DTML statements embedded within it (much like a PHP
script, which has PHP commands embedded within the markup).
If you have some familiarity with Zope, you'll already know about the HTML header
and footer objects; they are generic objects that can be used to place a standard
header and footer on every page. Enclosed within these is a regular HTML form,
albeit one which references another DTML Document when submitted. This DTML Document
is named FormProcessor, and it's going to handle the task of processing the data
entered into the form by the user.
<form action="FormProcessor" method="POST">
...
</form>
Here's what the form looks like: