Log in |
How to create a mail formZope makes it pretty easy to accomplish simple CGI style tasks with a little DTML. One common task everyone wants to do is to create a form that sends email. Here's a simple example showing how to create a mail form with Zope. All it takes is a Mail Host object, and two DTML Document Objects. Start by creating a Mail Host object. This object will allow Zope to send email. If you have already defined a Mail Host object, skip to the next step. You probably want to create this object at the top level of Zope so that all objects will have access to mail facilities. To create a Mail Host, choose "Mail Host" from the pop-up list of objects to add, and click "Add". You will next need to define your Mail Host. The import thing to specify is the SMTP Host. This should be the name of a computer which you can use to send mail. It may be the same as the localhost computer. Create a Mail HostNext create two documents, one to collect the data, and one to send the mail. You can create these Documents at any level in Zope that can acquire the Mail Host. Let's call the form Document <!--#var standard_html_header--> <H2>We want your input!</H2> <form action="SendFeedback" method="post"> Your Name: <input type="text" name="name" size="40"> <br> <textarea name="comments" rows="10" cols="50"> Type your comments here. </textarea><br> <input type="submit" value="Send Feedback"> </form> <!--#var standard_html_footer--> As you can see it defines a form whose action is The form defines two variables, Create a Form The <!--#var standard_html_header--> <!--#sendmail mailhost="MailHost"--> To: Feedback Recipient <[email protected]> From: Zope Feedback Form <[email protected]> Subject: Feedback from the web Feedback from : <!--#var name--> Comments: <!--#var comments--> <!--#/sendmail--> <h1>Thank you for your input!</h1> <p>Your comments have been sent.</p> <!--#var standard_html_footer--> This Document consists of two parts, the first part inside the The second part of the Document displays a confirmation message to the user which lets them know that their comments have been sent. Create a Form Processor As it is you have everything you need to build a working mail form. The only missing
ingredient at this point is deciding on a permissions policy. By default, only
users with the We could change the permission settings on our Mail Host, but this would defeat the conservative default policy and might not be appropriate for the whole site. Instead we can solve this problem with "Proxy roles". Proxy roles define additional roles for a Document. Normally a Document can only access resources if the current user has adequate permissions. Proxy roles allow a Document to behave as though the current users had additional roles. So if you give our To set the Proxy-roles, click the "Proxy" tab on the management screen while editing
the Setting PermissionsThat's it, you've just built a feedback form. Now test the mail form to make sure it works. The most likely problem that you will encounter is that you may not have selected the right computer for your SMTP host. You may have to contact your system administrator to find out the correct configuration. Testing the Mail Form |