Web Authoring
  Home arrow Web Authoring arrow Page 7 - Dreamweaver MX 2004 Extensions
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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? 
WEB AUTHORING

Dreamweaver MX 2004 Extensions
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 47
    2004-07-06

    Table of Contents:
  • Dreamweaver MX 2004 Extensions
  • Managing Extensions with the Macromedia Extension Manager
  • Yaromat Check Form
  • Build a Simple Survey Form
  • Massimocorner CF Upload
  • Dreamweaver’s Server Behavior Builder
  • Build Server Behavior Code and Interface
  • Distributing Server Behavior

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


    Dreamweaver MX 2004 Extensions - Build Server Behavior Code and Interface


    (Page 7 of 8 )

    Building the Server Behavior Code

    The following listing is the ColdFusion code we are going to turn into a server behavior (CFmailer.cfm):

    <cfif isdefined("form.fieldnames")>
      <cfset mail_body = "">
      <cfset cr = Chr(13) & Chr(10)>
      <cfloop index="form_element" list="#form.fieldnames#">
        <!--- Append each form element to message body ---> 
        <cfset mail_body = mail_body & form_element & ": " & Evaluate(form_element) & cr>
      </cfloop> <cfmail to="info@mysite.com" from="myform@mysite.com" subject="Contact Form">
        #mail_body#
      </cfmail>
      <cfset mail_redirect="success.cfm">
      <cfif mail_redirect NEQ "">
        <cflocation url="#mail_redirect#">
      </cfif>
    </cfif>

    The code starts by checking that the Form.Fieldnames variable exists. If so, it loops over each form field, adding their names and values to the message body (the mail_body variable), which will be sent as an e-mail by using the <cfmail> tag. After the message has been sent, the <cflocation> tag will stop the code execution and open a new page, as long as the mail_redirect variable is not empty.

    For the sake of the example, when turning the preceding ColdFusion code into a server behavior, you will convert only the to and from attributes of the <cfmail> tag and the value of the mail_redirect variable into custom parameters, although it is possible to change other parts of the code, such as the subject attribute.

    1. Start by choosing + -> New Server Behavior from the Server Behavior panel. The New Server Behavior dialog window should appear, as shown in Figure 9-13.


      Figure 9-13.
      Specifying the Document Type and Name of your server behavior

      Make sure ColdFusion is selected in the Document Type drop-down menu and enter CF Form Mailer in the Name field.

      Checking the “Copy existing server behavior” option will enable the “Behavior to copy” drop-down menu, which shows a list of all the avail able server behaviors we can copy from. You don’t want to copy a server behavior in this case, so leave it unchecked.

    2. Now click OK, and the main dialog window of the Server Behavior Builder will appear, which should look like Figure 9-14.
       

      Figure 9-14. The main Server Behavior Builder dialog box

    3. Click on the + sign to add a new code block. Dreamweaver will name it CF Form Mailer_block1. Click OK to accept this name.
    4. Insert the CFML Form Mailer code (CFmailer.cfm) into the Code Block field.
    5. Now it’s time to convert part of the code into some custom parameters. You want to be able to define the values of the <cfmail> tag’s first two attributes and to choose which URL to redirect users to after they submit the form. Highlight the <cfmail> tag’s first attribute value (info@mysite.com) and click on the Insert Parameter in Code Block button. The dialog box in Figure 9-15 appears.


      Figure 9-15.
      Inserting a parameter in the code block

      Enter Send Form To in the Parameter Name field and click OK. The chosen parameter name will be inserted into the code block surrounded by @@ blocks, replacing the info@mysite.com address.

    6. Repeat step 5, this time replacing myform@mysite.com with From, and replacing success.cfm (which is the value of the mail_redirect attribute of the <cfset> tag) with Go To Page.
    7. A good place to insert the server behavior is at the top of the page containing the form to be posted. For this reason, select Above the <html> Tag from the Insert Code pop-up menu in the Main Server Behavior Builder dialog box, then choose The Beginning of the File from the Relative Position menu.

    The Insert Code and Relative Position menus are related. The values available for the latter directly depend on the value chosen for the former. To learn more about code block positioning, please consult the Positioning code blocks section of the Using Dreamweaver documentation or the Participant EDML files section of the Extending Dreamweaver documenation, both available from Dreamweaver’s Help menu.

    Now all we have left to do in this dialog box is set some advanced options. Click on Advanced to display the Server Behavior Builder’s advanced options.

    Make sure the Identifier checkbox is selected so that the server behavior will be recognized by Dreamweaver and displayed on the Server Behaviors panel. The Server Behavior Title field is where you define the name your server behavior will appear under in the Server Behaviors panel, and the Code Block pop-up menu defines which code block will be highlighted when the server behavior is selected. Lastly, change the default [No Selection] value with CF Form Mailer_block1 and click on Next.

    Building the Server Behavior Interface

    We have covered the first step of making your server behavior. Next you must specify an HTML interface that you will use to enter custom parameter values into the server behavior. You don’t have to actually build a GUI yourself; you just specify what you want to appear in it, then Dreamweaver does most of the hard work.

    1. The dialog box shown in Figure 9-16 should now be present in Dreamweaver.


      Figure 9-16.
      The dialog box that allows you to specify how the GUI (dialog box) for your server behavior will look

      Select the Go To Page parameter. A small down arrow will appear at the right of its value in the Display As column. Click on the arrow to display all the available interface controls for user input.

    2. Because the Go To Page parameter defines which URL users are sent to after the form is posted, choose URL Text Field.
    3. The up and down arrows to the top-right corner of the main dialog change the order in which the parameters appear on the final HTML interface. Leave the Go To Page parameter selected and click on the down arrow to move it to the bottom of the list. Click OK.

    The CF Form Mailer server behavior should have been added the Server Behaviors panel, and is ready to be applied to any page you choose. The main dialog of your newly created server behavior should look like Figure 9-17. Try it out on a form of your own!


    Figure 9-17.
    Your new server behavior’s dialog box

    What Files Compose the Server Behavior?

    If you now look into the ServerBehaviors/ColdFusion folder in your Dreamweaver Configuration directory, you will find three new files that have just been generated by the Server Behavior Builder.

    The three new files are as follows:

    • CF Form Mailer.edml: This file is the participants group EDML file for your CF Form Mailer server behavior. If you open it with a text editor, you will see that it contains information about which version of Dreamweaver created it, and the text that will appear in the Server Behaviors panel after you apply the server behavior to a page. It also contains a list of all the participant EDML files.

    • CF Form Mailer_block1.edml: This file is a participant EDML file and contains all the information needed by Dreamweaver to distinguish it as a code block and to correctly apply it to files when the server behavior is applied.

    • CF Form Mailer.htm: This is the interface of the CF Form Mailer main dialog that appears when the server behavior is called within Dreamweaver. Because it is simple HTML, you can edit it to create a more satisfactory user interface if wished.

     

    This chapter is from ColdFusion Web Development with Macromedia Dreamweaver MX 2004, by Jen and Peter deHaan et al. (Apress, 2004, ISBN: 1-59059-237-9). Check it out at your favorite bookstore today.

    Buy this book now.

    More Web Authoring Articles
    More By Apress Publishing


     

    WEB AUTHORING ARTICLES

    - Yahoo Pipes: Worth a Look
    - Completing an EAR
    - Building and Deploying an EAR
    - New Nuke Security Sentinel: Worth Taking a C...
    - Administering Your CMS-Based Web Site
    - What You Need to Know Before Using a CMS
    - Introducing the Google Maps API
    - An Overview of the Yahoo User Interface Libr...
    - Basic configuration of osCommerce, concluded
    - Basic configuration of osCommerce, continued
    - Basic configuration of osCommerce
    - Deploying your Site with PHPEclipse, continu...
    - Deploying your Site with phpEclipse
    - Macromedia Captivate Review
    - Macromedia and Adobe Planning to Tie the Knot







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek