<!--- 
  Filename:     SearchForm.cfm
  Created by:   Nate Weiss (NMW)
  Date Created: 2/18/2001
  Please Note:  Maintains "last" search via Client variables
--->

<!--- When user submits form, save search criteria in Client var --->
<CFIF IsDefined("Form.SearchCriteria")>
  <CFSET CLIENT.LastSearch  = Form.SearchCriteria>
  <CFSET CLIENT.LastMaxRows = Form.SearchMaxRows>
<!--- If not submitting yet, get prior search word (if possible) --->  
<CFELSEIF IsDefined("CLIENT.LastSearch") AND IsDefined("CLIENT.LastMaxRows")>
  <CFSET SearchCriteria = CLIENT.LastSearch>
  <CFSET SearchMaxRows  = CLIENT.LastMaxRows>
<!--- If no prior search criteria exists, just show empty string --->  
<CFELSE>
  <CFSET SearchCriteria = "">
  <CFSET SearchMaxRows  = 10>
</CFIF>



<HTML>
<HEAD><TITLE>Search Orange Whip</TITLE></HEAD>
<BODY>
  <H2>Search Orange Whip</H2>

  <!--- Simple search form, which submits back to this page --->
  <CFFORM ACTION="#CGI.SCRIPT_NAME#" METHOD="Post">
    
    <!--- "Search Criteria" field --->
    Search For:
    <CFINPUT NAME="SearchCriteria" VALUE="#SearchCriteria#" 
      REQUIRED="Yes" 
      MESSAGE="You must type something to search for!">  
    
    <!--- "Submit" button --->
    <INPUT TYPE="Submit" VALUE="Search"><BR>

    <!--- "Max Matches" field --->    
    <I>show up to
    <CFINPUT NAME="SearchMaxRows" VALUE="#SearchMaxRows#" SIZE="2"
      REQUIRED="Yes" VALIDATE="integer" RANGE="1,500"
      MESSAGE="Provide a number from 1-500 for search maximum."> 
    matches</I><BR>
  </CFFORM>

  <!--- If we have something to search for, do it now --->
  <CFIF SearchCriteria NEQ "">
    <!--- Get matching film entries from database --->
    <CFQUERY NAME="GetMatches" DATASOURCE="#DataSource#">
      SELECT FilmID, MovieTitle, Summary 
      FROM Films
      WHERE MovieTitle LIKE '%#SearchCriteria#%'
         OR Summary    LIKE '%#SearchCriteria#%'
      ORDER BY MovieTitle
    </CFQUERY>

    <!--- Show number of matches --->
    <CFOUTPUT>
      <HR><I>#GetMatches.RecordCount# records found for 
      "#SearchCriteria#"</I><BR>
    </CFOUTPUT>
    
    <!--- Show matches, up to maximum number of rows --->
    <CFOUTPUT QUERY="GetMatches" MAXROWS="#SearchMaxRows#">
      <P><B>#MovieTitle#</B><BR>
      #Summary#<BR>
    </CFOUTPUT>
  </CFIF>
</BODY>
</HTML>

