Lesson 3 - Forms and Queries


When creating queries with Cold Fusion you will normally want to provide users with the ability to customize the data retrieved by the query. You do this by providing an HTML form which allows users to specify custom query criteria.

The HTML form code displayed below implements a simple select box which allows the user to specify a department to view a list of courses for:

 <FORM 

   ACTION="/~wsapi/cfusion?Template=/cfstand/tutorial/step3b.dbm" 
   METHOD=POST >
       
   Department: <SELECT NAME="Department_ID">  
                 <OPTION VALUE="BIOL" SELECTED> Biology
                 <OPTION VALUE="CHEM"> Chemistry
                 <OPTION VALUE="ECON"> Economics
                 <OPTION VALUE="MATH"> Mathematics  
               </SELECT> 

   <INPUT TYPE="submit" VALUE="Show Courses">   
       
 </FORM>

Similar to the previous example, a template file (step3b.dbm) is used to retrieve and format the data. However, in this case, the template is going to use the value entered by the user in the select box to display the courses of the appropriate department.

Select a Department and press the Show Courses button to see the results of the query:

    Department:     
    


[ Cold Fusion Tutorial ]