Introduction to ColdFusion Markup Language, concluded
If you want to get a good start on learning ColdFusion, look no further. This article covers a whole bunch of CFML tags and some basic functions. It is the second of two parts, and excerpted from chapter three of the book ColdFusion Web Development with Dreamweaver MX 2004, written by Jen and Peter deHaan et al. (Apress; ISBN: 1590592379).
Introduction to ColdFusion Markup Language, concluded - Collection Loop (Page 3 of 6 )
The final loop type loops over a collection, or structure. Structures (sometimes referred to as "associative arrays" in other programming languages) are containers for data, and that data is accessed by using what is called a key. In the following example demonstrates looping over a structure named#CGI#and accessing its contents by providing the key to the structure. The CGI structure is a special structure containing run-time information created by the ColdFusion Server. In fact, every "scope" (variable prefix) is exposed to your page as a structure. You can loop over "form," "url," "variables," and so on. For each iteration through the loop, we are setting a variable called#item#that is used to hold the current key. We cover structures in more detail in Chapter 4.
Enter the following code block into a new Dreamweaver document (colloop.cfm):
Test the document in a browser, and you will see all of the CGI variables in the window, as shown in Figure 3-13. (Only a small sample is shown here.)
Figure 3-13. Using a collection loop to output all the CGI variables
<cfmail>
We briefly touched on<cfmail>in Chapter 1.This tagis responsible for sending e-mails from within ColdFusion applications to a designated e-mail address. Unlikemailto: linksin HTML, the mail is sent via an SMTP mail server and not the users mail client and mail server. Typically,<cfmail>is used to send news-letters and reminders to users, or error messages to administrators.
The basic syntax for the<cfmail>tag is as follows (cfmail.cfm):
<cfmail to="admin@yoursite.com" from=name@visitor.com subject="This is the subject"> The message of the e-mail goes here. </cfmail>
Several other options for the<cfmail>tag allow you to attach files to the e-mail or specify whether you want to send an e-mail with HTML formatting, and so on. However, we go through only the basic options here. Follow these steps to use this tag in Dreamweaver.
Create a new ColdFusion file in Dreamweaver MX, click on the CFML Advanced tab, and click on the CFMAIL icon, which is the little envelope icon ninth from the left on the toolbar, as shown in Figure 3-14. This will cause the Tag Editor - Cfmail dialog box to open.
Figure 3-14. The Dreamweaver MX 2004 Insert bar with the advanced CFML functions shown and the cfmail button illustrated
In the dialog box General tab, you can set the values of the To, From, and Subject attributes by using the appropriate text fields, as shown in Figure 3-15. You can also set CC and BCC addresses.
Figure 3-15. The Tag Editor - Cfmail dialog box's General tab
Next, click on the Message Body tab, fill in the body of the e-mail, and from the drop-down menu select whether you are sending a plain text e-mail or an HTML e-mail.
If you haven't defined a mail server within the ColdFusion Administrator, you can click on the Server Settings section and define your mail server, port, and timeout settings. If you try sending e-mails without defining server settings in the Administrator or within the tag, the e-mail will not be sent and will end up in an undeliverable folder.
Click on the OK button, and the code (as shown previously) is automatically inserted into the Document window.