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 - The cfform tag (Page 6 of 6 )
We will now look at a brief comparison to demonstrate the advantages of ColdFusion forms over their HTML counterparts.
Enter the following code into a new file and save it asforms.cfm:
<!-- HTML --> <form action="action.cfm" method="post"> UserName: <input type="Text" name="UserName"><br /> Password: <input type="Password" name="Password"><br /> <input type="Submit" value="Login"> </form> <!-- CFML --> <cfform action="action.cfm" method="post"> UserName: <cfinput type="Text" name="UserName" required="Yes" message="Please Enter your user name."><br /> Password: <cfinput type="Password" name="Password" required="Yes" message="Please enter your password."><br /> <input type="Submit" value="Login"> </cfform>
The preceding code creates two forms, as you can see in Figure 3-17.
Figure 3-17. Two identical-looking forms, but one is a standard HTML form and one is a ColdFusion form
Figure 3-18. Form validation is really simple to add to ColdFusion forms.
ColdFusion also allows you to specify the data type for the<cfinput>. Now let's take a look at another example. Create a new.cfmfile, enter the following code into it, and save it asageform.cfm:
<cfform action="action.cfm" method="post"> <cfinput name="Age" type="text" size="2" maxlength="3" range="0,100" required="yes" message="Please enter a valid integer" validate="integer"> <input type="submit" value="Go"> </cfform>
Test this in a browser, and you will see something similar to Figure 3-19.
Figure 3-19. Our ColdFusion age form
Does not enter a value
Enters a non-integer
Enters a number that is out of the allowed range
The user is not allowed to submit the form until the field passes the validation, as shown in Figure 3-20.
Figure 3-20. If the user does not enter a valid integer, the custom error message appears.
This has been a fairly quick introduction to some of the more common CFML tags. You should now have a better understanding of the CFML syntax and have a very basic knowledge of the difference between ColdFusion tags and ColdFusion functions.
There are certainly a lot of tags that we don't have the space to explain in detail; you can find a complete list of tags and functions (and detailed explanations) athttp://livedocs.macromedia.com/. Before proceeding, you should also understand the difference between the<cfset>and<cfparam>tag, and understand and be familiar with basic<cfif>syntax; these will be used heavily throughout the rest of the book.
You should now be relatively familiar with the following CFML tags (remember that practice makes perfect):
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.