Home arrow Zope arrow Page 6 - Form Processing With Zope

You've Got Mail! - 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
Finally, how about a complete example to wrap all this up? Here's the form:

<dtml-var standard_html_header> <table border=0 cellspacing=5 cellpadding=5> <form action="FeedbackFormProcessor" method="POST"> <tr> <td valign="top">Name:</td> <td><input name="name:string"></td> </tr> <tr> <td valign="top">Email address:</td> <td><input name="email:required"></td> </tr> <tr> <td valign="top">Comments:</td> <td><textarea name="comment:text" cols="30" rows="6"></textarea></td> </tr> <tr> <td colspan=2 align=center><input type="Submit" name="submit" value="Send!"></td> </tr> </table> </form> <dtml-var standard_html_footer>
And here's what it looks like:



As you can see, this is a simple feedback form for a Web site. When a user submits it, the information entered into it should be automagically emailed to the site's Webmaster.

How is this done in Zope? Very simple. First, create a new Mail Host object (I've called mine "LocalRelay"), and assign it appropriate values for your SMTP server. Then, create a FeedbackFormProcessor, which uses this Mail Host object to send the contents of the form to a specified email address.

Here's the code:

<dtml-var standard_html_header> <dtml-sendmail mailhost="LocalRelay"> To: webmaster@domain.com From: <dtml-var email> Subject: Feedback on <dtml-var SERVER_URL> Name: <dtml-var name> Email address: <dtml-var email> Comment: <dtml-var comment> -- URL: <dtml-var URL> Remote address: <dtml-var REMOTE_ADDR> User agent: <dtml-var HTTP_USER_AGENT> </dtml-sendmail> Your feedback was sent successfully. Thank you for your comments! <dtml-var standard_html_footer>
In this case, the <dtml-sendmail> directive is used to tell Zope that the contents of the block are to be sent out as email via the specified Mail Host. You must ensure that the email message includes "To", "From" and "Subject" headers, or else either Zope or your mail server will barf. In addition to these three mandatory headers, you can also specify additional, optional headers, such as "Cc", "Reply-To" and so on.

Notice how I've included a few built-in variables in the email message. This is useful to provide the site's Webmaster with some additional information on the client used to send the feedback.

In case you have difficulty configuring a Mail Host, you can also use this alternative construction:

<dtml-sendmail smtphost="my.mail.server" port="25" > ... </dtml-sendmail>
Once the email message has been sent, a message is displayed to the user confirming message delivery.

If you're going to be using a lot of feedback forms, you might want to consider making the recipient email address a property, so that you can refer to it as a variable rather than hard-wiring it into the DTML Document code itself.

 
 
>>> 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: