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

Chapter 14. Case Study: Corporate Intran... > Creating the Search Interface

Creating the Search Interface

The public face of the corporate directory application is the search interface that all employees can use to look up fellow employees. The interface developed here will allow a user to search by last name or by department, but you can adapt the concepts to search on other fields as well. Listing 14.1 shows the code for the script that generates the initial page of the search function.

Listing 14.1. search.cfm—Initial Search Page


     Employee Directory Case Study

     This script generates a page that allows the user to search for
     employees by name or by department. Department names are queried
     from the supporting database and displayed by means of a drop-down

     The form has two submit buttons, so it is important to name each one
     so that the processing script can figure out which one was clicked.



     Query out the department names and primary key values.


<cfquery datasource="employees" name="qGetDepts">
SELECT DepartmentID, DepartmentName
FROM Departments
ORDER BY DepartmentName


<title>XYZ Manufacturing Employee Directory</title>


<h1>XYZ Manufacturing Employee Directory</h1>
<form action="searchresults.cfm" method="post">

<p><b>Search By Last Name</b></p>

<p>Enter all or part of an employee's last name below
and click the "Search" button.</p>

<input type="text" name="searchName" size="20">


     Naming the first submit button distinguishes it
     from the second one below.


<input type="submit" name="byName" value="Search">

<p><b>Search By Department</b></p>

<p>Select a department from the list below and click the "Search" button
to see all employees from that department.</p>

<select name="departmentID" size="1">


     Use a <cfoutput> tag to dynamically generate the options
     in the drop-down list. The value passed by each option is
     a comma-delimited list including the department's primary
     key value and name. This saves having to do an additional
     query in the processing script.


<cfoutput query="qGetDepts">
<option value="#DepartmentID#,#DepartmentName#">#DepartmentName#</option>



     The second submit button is named as well.


<input type="submit" name="byDept" value="Search">







Not a subscriber?

Start A Free Trial

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