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:
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 #FORM.name#, 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.