Makeover Exercise

Team-Fly    

ColdFusion® MX: From Static to Dynamic in 10 Steps
By Barry Moore
Table of Contents
Step 7.  Using Email with ColdFusion MX


It's time to put our knowledge of <CFMAIL> to some good use. In this portion of our web site makeover, we will use <CFMAIL> to create an action page to process our feedback form. In addition, as an added measure of security, we are going to get ColdFusion to send the webmaster a notification message whenever product information is changed or news items are added or modified via our administration interface.

Feedback Form Action Page

We currently have a feedback form with which users can submit comments. However, at the moment we have nothing to process the submitted form information. Let's create an action page to handle user feedback.

  1. Navigate to your NewSite folder and open Feedback\FeedbackForm.cfm in your text editor.

    Because any feedback is better than no feedback and there is not much need for form validation, we will leave this form as a normal HTML-based form.

    In the main body text cell, find the ACTION attribute of the feedback form's <FORM> tag. Change the ACTION attribute to FormAction.cfm. Note the names of the various input fields of the form.

     <FORM ACTION="FormAction.cfm" METHOD="POST" >
  2. Open a new file in your text editor and type the code in Listing 7.4.

    Listing 7.5 FormAction.cfm
     <!--- File:            FormAction.cfm  Description:     Process information from our feedback form  Author:  Created:  --->  <!--- use CFMAIL to send feedback from the form          add you email address to the TO attribute          add your SMTP server to the SERVER attribute--->  <CFMAIL TO="your.emailaddress.here"          FROM="admin@beelze-bubba.com"          SUBJECT="Website Feedback"          SERVER="your.mailserver.here">Webmaster Email:  Feedback has been posted at the Beelze-Bubba website.  Date: #DateFormat(Now(),"DD-MMM-YYY")#  Name: #FORM.Name#  Email: #FORM.Email#  Phone: #FORM.Phone#  Subject: #FORM.Subject#  Comments:  #FORM.Comments#  ------------------------------------------------------------- This is an automated email from the Beelze-Bubba Web server.  Please do not reply.  </CFMAIL>  <!--- display confirmation message --->  <HTML>    <HEAD>        <TITLE>Thank You For Your Feedback</TITLE>    </HEAD>    <BODY>    <IMG src="/books/4/16/1/html/2/../images/logo_sml.gif" ALT="" WIDTH="133" HEIGHT="50" BORDER="0"><BR>    <HR COLOR="#990033" NOSHADE>    <CFOUTPUT><H2>#FORM.Name#, Thank you for your feedback.</H2></CFOUTPUT>    <A HREF="../Index.cfm">return to main Beelze-Bubba website</A>    </BODY>  </HTML>
  3. Save this file as FormAction.cfm in your NewSite\Feedback folder.

    This file creates an email to the webmaster with the contents of the submitted feedback form. Note we use the Now() function to set the date of the form submission. After the message has been emailed, we show the user a confirmation page and provide a link back to the main web site.

  4. Browse to the Beelze-Bubba feedback form, fill in the form with information, and submit it as illustrated in Figure 7.10.

    Figure 7.10. The Beelze-Bubba feedback form.

    graphics/07fig10.gif

  5. Wait a few moments and check your email. You should have a message similar to the one in Figure 7.11.

    Figure 7.11. A Beelze-Bubba automated email to the webmaster.

    graphics/07fig11.gif

Notification Messages

In Step 6, "Updating, Inserting, and Deleting Database Records," we created an interface for Beelze-Bubba employees to change database information via web forms. Later in this book, we will add password protection to that section of the web site so that only people with the appropriate username and password will have access. However, this does not stop someone with the appropriate credentials from being naughty.

Suppose a disgruntled employee quits, goes home, and changes all the prices on the web site before his password can be deactivated. If we aren't monitoring the web site carefully, it could be days before we notice that the information has been changed.

To prevent this scenario, we are going to add an email notification feature to the web site. Whenever someone updates product information or adds a news item, ColdFusion will notify the webmaster of the change.

To do this, we are going to have to modify the action pages we created in Step 6.

  1. In your text editor, navigate to the NewSite\Admin folder and open the ProductUpdate.cfm file.

  2. Just below the UPDATE query, add the following code. Substitute your email address and mail server settings in the appropriate attributes.

     <!--- automated email notification to the webmaster --->  <CFMAIL TO="your.emailaddress.here"          FROM="admin@beelze-bubba.com"          SUBJECT="Product Update"          SERVER="your.mailserver.here">Webmaster Email:  There has been an update to product information for  #Trim(FORM.Name)# - Category: #FORM.Category#  http://CGI.Server_Name#/NewSite/Products/ProductDetail.cfm?pid=#FORM.ProductNo#  ---------------------------------------------------------------------- This is an automated email from the Beelze-Bubba Web server.  Please do not reply.  </CFMAIL>
  3. Save the File. Browse to the http://localhost/NewSite/Admin/AdminHome.cfm page and follow the links to update the information for one of the products.

  4. Wait a few moments and then check your email. You should receive a message similar to the one in Figure 7.12.

    Figure 7.12. A webmaster notification email.

    graphics/07fig12.gif

See if you can add similar notification messages to the News Item Insert and Update action pages. If you get stuck, you can check yourself against the files in the CompletedFiles\MakeoverExercises\Step07 folder.


    Team-Fly    
    Top
     



    ColdFusion MX. From Static to Dynamic in 10 Steps
    ColdFusion MX: From Static to Dynamic in 10 Steps
    ISBN: 0735712964
    EAN: 2147483647
    Year: 2002
    Pages: 140
    Authors: Barry Moore

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net