Zope
  Home arrow Zope arrow Page 6 - Form Processing With Zope
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 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? 
Google.com  
ZOPE

Form Processing With Zope
By: Team Melonfire, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    2002-02-26


    Table of Contents:
  • Form Processing With Zope
  • Driving Under The Influence
  • Stringing Things Along
  • Running On Empty
  • In The Raw
  • You've Got Mail!
  • Endgame

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Form Processing With Zope - You've Got Mail!
    ( Page 6 of 7 )

    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
     

       

    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-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek