![]() ![]() ![]() |
Creating dynamic Web pages with ColdFusion is as straightforward as creating ordinary Web pages. The following sections will step you through two simple examples designed to introduce you to ColdFusion. If you're feeling more adventurous, take a look at the sections that deal with the example applications installed with ColdFusion in
This example shows how ColdFusion uses a form field variable entered into an HTML form.
Using ColdFusion Studio, create two files in the \cfdocs
directory located in your Web server document root directory:
hellopage1.cfm
hellopage2.cfm
hellopage1.cfm
file, type the following HTML and CFML, or copy and paste into a new document if you are viewing this online:
<HTML> <HEAD> <TITLE>Hello World Page One</TITLE> </HEAD> <BODY> <H2>Enter Your Message</H2> <HR> <FORM ACTION="hellopage2.cfm" METHOD="post"> <INPUT TYPE="text" SIZE="30" NAME="HelloText"> <INPUT TYPE="submit" VALUE="Submit"> </FORM> </BODY> </HTML>
hellopage2.cfm
file type the following HTML and CFML and save:
<HTML> <HEAD> <TITLE>Hello World Page Two</TITLE> </HEAD> <BODY> <CFOUTPUT> <H2>#Form.HelloText#</H2> </CFOUTPUT> </BODY> </HTML>
http://127.0.0.1/cfdocs/hellopage1.cfm
When the form was submitted in the first page, a variable was created (Form.HelloText) and passed to the second page where it was resolved and displayed.
The following example shows you how to create an application page using data from the ColdFusion cfsnippets data source.
courses.cfm
in the \cfdocs\
directory located in your Web server root document directory.
courses.cfm
file and save:
<!--- Start of Database Query ---> <CFQUERY NAME= "CourseList" DATASOURCE= "cfsnippets"> SELECT * FROM CourseList </CFQUERY> <!--- End of Query ---> <HTML> <HEAD> <TITLE>Department List</TITLE> </HEAD> <BODY> <H2>Course List</H2> <HR> <!--- Start of Output Block ---> <CFOUTPUT QUERY="CourseList"> (#CourseNumber#)</B> #CourseName#<BR> </CFOUTPUT> <!--- End of Output Block ---> </BODY> </HTML>
Note the use of the comment convention used in ColdFusion pages: <!---
and
--->
. ColdFusion comments use a form similar to HTML comments, but with an
additional hyphen.
http://127.0.0.1/cfdocs/courses.cfm
In this example, the CFQUERY tag used the SQL SELECT statement to retrieve all the data from the CourseList table. The CFOUPUT tag then referenced the CourseNumber and CourseName columns returned by the query, for display.
Once again, here's the query part:
<!--- Start of Database Query ---> <CFQUERY NAME= "CourseList" DATASOURCE= "cfsnippets"> SELECT * FROM CourseList </CFQUERY> <!--- End of Query --->
Here's the output part:
<CFOUTPUT QUERY="CourseList"> (#CourseNumber#)</B> #CourseName#<BR> </CFOUTPUT>
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.