Trying It Yourself

Codegen is OK for some tasks (and is wonderful for rapid prototyping), but more often than not it won't be enough. This is why most of this book discusses coding. To give you a taste of what's to come, try this small (and very simple) application. I won't go into the details of the code itself; for now, concentrate on creating and executing CFM files so they work. If you can get all these to function, you'll have a much easier time working through the book.

The bday application is really simple; it prompts you for your name and date of birth and calculates your age, using simple date arithmetic. The application is made up of two files:

  • bday1.cfm (shown in Listing 4.1) is the form that prompts for the name and date of birth.

  • bday2.cfm (shown in Listing 4.2) processes the form and displays the results.

Using Dreamweaver MX, create these two new files, saving them both in the 4 directory. Then enter the code below in each file exactly as it appears hereyour files should contain this code and nothing else.

Listing 4.1. bday1.cfm
 <html> <body> <form action="bday2.cfm" method="post"> Name: <input type="text" name="name"> <br> Date of birth: <input type="text" name="dob"> <br> <input type="submit" value="calculate"> </form> </body> </html> 

The code in bday1.cfm is simple HTMLthere's no ColdFusion code at all. In fact, you could have named the file with an HTML extension and it would have worked properly.

bday1.cfm contains an HTML form with two form fields: name for the user name and dob for the date of birth.

Listing 4.2. bday2.cfm
 <html> <body> <cfoutput> Hello, you are #DateDiff("YYYY", FORM.dob, Now())#. </cfoutput> </body> </html> 

The code in bday2.cfm is a mixture of HTML and CFML. The name form field displays the Hello message, and the dob field calculates the age.

To try the application, open a browser and go to the following URL:



If you aren't using the integrated HTTP server, adjust the URL accordingly.

Another form, similar to the one in Figure 4.18, will prompt you for your name and date of birth. Fill in the two fields, and then click the form submission button to display your age (see Figure 4.19).

Figure 4.18. ColdFusion forms are created using standard HTML tags.

Figure 4.19. ColdFusion generates output displayed in a browser.

Was that a little anticlimactic after the Dreamweaver MXgenerated application? Perhaps. But you've now learned all you need to know about creating, saving, and executing ColdFusion applications.

Macromedia Coldfusion MX 7 Web Application Construction Kit
Macromedia Coldfusion MX 7 Web Application Construction Kit
ISBN: 321223675
Year: 2006
Pages: 282 © 2008-2017.
If you may any questions please contact us: