User Guide

Table Of Contents
210 Chapter 10: Building and Using ColdFusion Components
Example: tempConversion.cfm
The ColdFusion page tempConversion.cfm is an HTML form in which the user enters the
temperature to convert, and selects the type of conversion to perform. When the user clicks the
Submit button, ColdFusion performs the actions on the processForm.cfm page. The file
tempConversion.cfm, which should be in the same directory as convertTemp.cfc, consists of the
following:
<cfform action="processForm.cfm" method="POST">
Enter the temperature:
<input name="temperature" type="text"><br><br>
Select the type of conversion:<br>
<select name="conversionType">
<option value="CtoF">Celsius to Farenheit</option>
<option value="FtoC">Farenheit to Celsius</option>
</select><br><br>
<input name="submitform" type="submit" value="Submit">
</cfform>
Example: processForm.cfm
The ColdFusion page processForm.cfm calls the appropriate component method, based on what
the user entered in the form on the tempConversion.cfm page. It should be in the same directory
as convertTemp.cfc.
<cfif #form.conversionType# is "CtoF">
<cfinvoke component="convertTemp" method="ctof" returnvariable="newtemp"
temp=#form.temperature#>
<cfoutput>#form.temperature# degrees Celsius is #newtemp# degrees
Farenheit.</cfoutput>
<cfelseif #form.conversionType# is "FtoC">
<cfinvoke component="convertTemp" method="ftoc"
returnvariable="newtemp" temp=#form.temperature#>
<cfoutput>#form.temperature# degrees Fahrenheit is #newtemp# degrees
Celsius.</cfoutput>
</cfif>
<cfreturn ((temp-32)*5/9)>
Defines the value that the method returns.
</cffunction>
Ends the method definition.
</cfcomponent>
Ends the component definition.
Code Description