<FORM METHOD="POST" ACTION="CFMQUERY.CFM">
METHOD="POST" simply means that the form is to be posted on the screen. ACTION="CFMQUERY.CFM" tells the form to run the Cold Fusion query file specified when the form is submitted for action (see below). This is where you specify the name of the Cold Fusion file to run when the user completes the form and submits it for action. For example, the complete Cold Fusion query example below can be named "CFMQUERY.CFM" and this form can launch it. This is always the first statement of the form.
The last two statements of the form are the ones that submit the form for processing. They are:
<INPUT TYPE="SUBMIT" VALUE="text on button">
</FORM>
Here is the button that results from the SUBMIT command. This button has "Press to Submit" as the VALUE.
Here is the HTML code to create the SELECT box.
<SELECT NAME="stateval" SIZE=3>
<OPTION VALUE="AZ">Arizona
<OPTION VALUE="CA" SELECTED>California
<OPTION VALUE="OR">Oregon
</SELECT>
The NAME="stateval" means that the variable "stateval" will be passed to the CFMQUERY.CFM Cold Fusion query. The actual value of "stateval" will be determined by which option the user clicks on. SIZE=3 means that the box displays only three of the options. This parameter sizes the box.
The OPTION VALUE="AZ" means that the variable "stateval" will have the value "AZ" when it is passed to CFMQUERY.CFM The state name Arizona is what appears in the Select box. SELECTED simply means that the California option is the one already selected - the default selection. This parameter is optional, but only one option can be selected. Yes, it's this easy!
This type of form input option requires that you determine all possible valid values in the data and provide them for the user to select from. Also, you must ensure that the values are consistent with the data. For example, in our Proj3data.mdb database, "AZ" is the abbreviation for Arizona. If you specify "AX" as the value, then no data for Arizona will ever be found.
Here is the HTML code to create the Radio Buttons.
<INPUT TYPE="RADIO" NAME="channel" VALUE="Retail" CHECKED>Retail Channel
<INPUT TYPE="RADIO" NAME="channel" VALUE="Wholesale">Wholesale Channel
The NAME and VALUE parameters have the same function as in the SELECT box above. CHECKED has the same meaning as SELECTED above - it specifies the default choice. By design, only one radio button can be checked at a time, making it ideal for our simple application.
Here is the HTML code to create the Check Boxes.
<INPUT TYPE="CHECKBOX" NAME="price" VALUE="Low" CHECKED>Low Price Range
<INPUT TYPE="CHECKBOX" NAME="price" VALUE="Mid">Mid Price Range
<INPUT TYPE="CHECKBOX" NAME="price" VALUE="High">High Price Range
The parameters are the same as the Radio Buttons.
<INPUT TYPE="RESET" NAME="Reset" VALUE="Click to Clear All Entries">
NAME simply specifies the button name, and VALUE specifies the text on the button.
<HTML>
<HEAD>
<TITLE>Simple Input Form and Cold Fusion Example</TITLE>
</HEAD>
<BODY>
<H3 ALIGN=CENTER>Select State to display</H3>
<P>
<FORM METHOD="POST" ACTION="CFMQUERY.CFM">
<SELECT NAME="stateval" SIZE=3>
<OPTION VALUE="AZ">Arizona
<OPTION VALUE="CA" SELECTED>California
<OPTION VALUE="OR">Oregon
<OPTION VALUE="NV">Nevada
</SELECT>
<INPUT TYPE="SUBMIT" VALUE="text on button">
</FORM>
<P>
</BODY>
</HTML>
This HTML file can be named "inputform.html" (or anything you want to name it)
Now we create the "cfmquery.cfm" Cold Fusion file referenced in the FORM command in the HTML file above. This is the file that the form will cause to execute that will query the ORDERS table for all data for the selected state, then display the data on the screen.
<HTML>
<HEAD>
<TITLE>Cold Fusion Example</TITLE>
<cfquery name = "salesinfo" datasource = "sds5_general">
SELECT STATE,CATEGORY,UNITS,NETAMT
FROM ORDERS
WHERE STATE = '#stateval#'
ORDER BY CATEGORY;
</cfquery>
</HEAD>
<BODY>
<H3 ALIGN=CENTER>List of Sales Data<H3>
<cfoutput query = "salesinfo">
#STATE# #CATEGORY# #NETAMT# <p>
</cfoutput>
<H4 ALIGN=CENTER>End of Sales Data List</H4>
</BODY>
</HTML>
This file MUST be named "cfmquery.cfm" because it is the file that is specified in the ACTION parameter in the FORM command in the HTML file. The file name can be anything as long as it is consistent with the name specified in the ACTION parameter in the HTML file.
The critical point to get here is the use of the variable "stateval". In the "inputform.html" document the form specified the variable "stateval" and the value of the variable is set when the user clicks on the option list. For example, if the user clicks on Arizona, the value of "stateval" is "AZ".
Look at the WHERE parameter in the SQL command above. The variable #stateval# is used in the criterion argument. Note that the variable #stateval# is within single quotes. Remember, text variable values must be within single quotes in the WHERE parameter. All data records with the variable STATE having the value "AZ" will be displayed. This is how Cold Fusion works. The variable value selected by the user is passed to SQL from the form, then Cold Fusion executes the SQL command against the database. Cold Fusion then displays all the data that meets the selection criterion. Yes, it's this simple!!!!!!!