• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Step 5. Using Forms with ColdFusion MX > Example 5.2: Building an Advanced Sear...

Example 5.2: Building an Advanced Search Form

In this example, we will build the form shown in Figure 5.9. We will add fields for users to enter first and last name information as well as the option to specify department information.

Open you text editor and enter the code in Listing 5.5 or open the completed Form2.cfm file from the CompletedFiles\Examples\Step05 folder.

Listing 5.5. Form2.cfm

File:             Form2.cfm 
Description:      Multi-field search form 

<!--- get department information for the select menu ---> 
<CFQUERY NAME="qDepartments" DATASOURCE="Staff"> 
      SELECT      DepartmentID, DepartmentName 
      FROM        Departments 
      ORDER BY    DepartmentName 

      <TITLE>HTML Form 2</TITLE> 
<H2>Employee Search Form</H2> 
      Search for an employee by entering their name,<BR> 
      or the first few letters of their name. <BR> 
      You can also specify a department if you wish 
      <!--- specify Action2.cfm as the action page ---> 
      <FORM ACTION="Action2.cfm" METHOD="post"> 
        <!--- input box to enter first name information ---> 
        First Name: 
        <INPUT TYPE="text" NAME="SearchFName" SIZE="20"><BR> 
        <!--- input box to enter last name information ---> 
        Last Name: 
        <INPUT TYPE="text" NAME="SearchLName" SIZE="20"><BR> 
        Select A Department: 
        <SELECT NAME="DepartmentID"> 
          <!--- include a choice to search all departments ---> 
            <OPTION VALUE="" SELECTED>All Depts</OPTION> 
            <!--- use query info to build list options ---> 
            <CFOUTPUT QUERY="qDepartments"> 
            <OPTION VALUE="#DepartmentID#">#DepartmentName#</OPTION> 
        <INPUT TYPE="submit" VALUE="Search"> 


Save this file into your Example\Step05 folder as Form2.cfm.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint