
184
DEVELOPING
COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Las
t
upda
te
d 8/5/2010
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 is 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. Place it in the same directory as convertTemp.cfc.
Code
Description
<cfcomponent>
Defines the component.
<cffunction name="ctof" output="false">
Defines the
ctof
method.
Indicates that this method does not display output.
<cfargument name="temp" required="yes"
type="numeric">
Creates the
temp
parameter of the
ctof
method. Indicates that it is required and
that the expected value is
numeric
.
<cfreturn ((temp*9)/5)+32>
Defines the value that the method returns.
</cffunction>
Ends the method definition.
<cffunction name="ftoc" output="false">
Defines the
ftoc
method.
Indicates that this method does not display output.
<cfargument name="temp" required="yes"
type="numeric">
Creates the
temp
parameter of the
ftoc
method. Indicates that it is required and
that the expected value is
numeric
.
<cfreturn ((temp-32)*5/9)>
Defines the value that the method returns.
</cffunction>
Ends the method definition.
</cfcomponent>
Ends the component definition.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...