I've been working with one of Ben Forta's examples and I'd like to modify it. In it's current form, the code (below) uses session variables to remember the last keyword that was queried. The action page and the result page are the same in this instance (i.e., the search is done and the user is returned to the same page, and the results appear below the search entry box).
But now I need to modify the CFFORM code so that rather than the user typing in a keyword, he simply chooses from a select-driven list. The dynmic list driven portion of the code I have, but I'm confused about how to incorporate the session variables needed to remember the selection.
Any help is appreciated.
-Rik
----------------------------------------------
Original (works)
<!--- When user submits form, save search criteria in Client variable --->
<CFIF IsDefined("Form.SearchCriteria"
>
<CFSET CLIENT.LastSearch = Form.SearchCriteria>
<!--- If not submitting yet, get prior search word (if possible) --->
<CFELSEIF IsDefined("CLIENT.LastSearch"
>
<CFSET SearchCriteria = CLIENT.LastSearch>
<!--- If no prior search criteria exists, just show empty string --->
<CFELSE>
<CFSET SearchCriteria = "">
</CFIF>
<CFSET PageStatus = "Search">
<CFFORM ACTION="#CGI.SCRIPT_NAME#" METHOD="Post" class="maintext">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="28%">
<!--- "Search Criteria" field --->
<span class="maintext2bold">Search</span><p>
<span class="maintext2">Enter keyword or phrase:<br>
</span>
<cfinput name="SearchCriteria" value="#SearchCriteria#"
required="Yes"
message="Your query is blank - please enter a word or phrase." class="maintext2">
</td>
<td width="34%" align="right" valign="bottom">
<!--- "Submit" button --->
<input name="Submit" type="Submit" class="button" value="Search"></td>
</tr>
<tr>
<td colspan="4"><hr noshade></td>
</tr>
</table>
</CFFORM>
<!--- If we have something to search for, do it now --->
<CFIF SearchCriteria NEQ "">
-------------------------------------------------
Modified to include a dynamic list (a mess)
<cfparam name="wsh_year" default="WSH_YEAR">
<cfparam name="id" default="id">
<CFQUERY NAME="get_ws" DATASOURCE="attro"
CACHEDWITHIN="#CreateTimeSpan(0,0,15,0)#">
SELECT system, wsh_year, id
FROM wsh
WHERE wsh_year = '2002'
ORDER BY system, wsh_year
</CFQUERY>
<CFQUERY NAME="GetWS" DATASOURCE="attro">
SELECT id
FROM wsh
</CFQUERY>
<!--- When user submits form, save search criteria in Client variable --->
<CFIF IsDefined("Form.SearchCriteria"
>
<CFSET CLIENT.LastSearch = Form.SearchCriteria>
<!--- If not submitting yet, get prior search word (if possible) --->
<CFELSEIF IsDefined("CLIENT.LastSearch"
>
<CFSET SearchCriteria = CLIENT.LastSearch>
<!--- If no prior search criteria exists, just show empty string --->
<CFELSE>
<CFSET SearchCriteria = "">
</CFIF>
<CFSET PageStatus = "Search">
<CFFORM ACTION="#CGI.SCRIPT_NAME#" METHOD="Post" class="maintext">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="28%">
<!--- "Search Criteria" field --->
<span class="maintext2bold">Search</span>
<p> <span class="maintext2">Select a system to cross reference:<br>
</span>
<cfinput name="SearchCriteria" class="dropdown"> <cfoutput query="get_ws"
option value="#get_ws.system#"
#get_ws.system# </CFOUTPUT>
required="Yes"
message="Your query is blank - please enter a word or phrase.">
</td>
<td width="34%" align="right" valign="bottom">
<!--- "Submit" button --->
<input name="Submit" type="Submit" class="button" value="Search"></td>
</tr>
<tr>
<td colspan="4"><hr noshade></td>
</tr>
</table>
</CFFORM>
<!--- If we have something to search for, do it now --->
<CFIF SearchCriteria NEQ "">
But now I need to modify the CFFORM code so that rather than the user typing in a keyword, he simply chooses from a select-driven list. The dynmic list driven portion of the code I have, but I'm confused about how to incorporate the session variables needed to remember the selection.
Any help is appreciated.
-Rik
----------------------------------------------
Original (works)
<!--- When user submits form, save search criteria in Client variable --->
<CFIF IsDefined("Form.SearchCriteria"
<CFSET CLIENT.LastSearch = Form.SearchCriteria>
<!--- If not submitting yet, get prior search word (if possible) --->
<CFELSEIF IsDefined("CLIENT.LastSearch"
<CFSET SearchCriteria = CLIENT.LastSearch>
<!--- If no prior search criteria exists, just show empty string --->
<CFELSE>
<CFSET SearchCriteria = "">
</CFIF>
<CFSET PageStatus = "Search">
<CFFORM ACTION="#CGI.SCRIPT_NAME#" METHOD="Post" class="maintext">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="28%">
<!--- "Search Criteria" field --->
<span class="maintext2bold">Search</span><p>
<span class="maintext2">Enter keyword or phrase:<br>
</span>
<cfinput name="SearchCriteria" value="#SearchCriteria#"
required="Yes"
message="Your query is blank - please enter a word or phrase." class="maintext2">
</td>
<td width="34%" align="right" valign="bottom">
<!--- "Submit" button --->
<input name="Submit" type="Submit" class="button" value="Search"></td>
</tr>
<tr>
<td colspan="4"><hr noshade></td>
</tr>
</table>
</CFFORM>
<!--- If we have something to search for, do it now --->
<CFIF SearchCriteria NEQ "">
-------------------------------------------------
Modified to include a dynamic list (a mess)
<cfparam name="wsh_year" default="WSH_YEAR">
<cfparam name="id" default="id">
<CFQUERY NAME="get_ws" DATASOURCE="attro"
CACHEDWITHIN="#CreateTimeSpan(0,0,15,0)#">
SELECT system, wsh_year, id
FROM wsh
WHERE wsh_year = '2002'
ORDER BY system, wsh_year
</CFQUERY>
<CFQUERY NAME="GetWS" DATASOURCE="attro">
SELECT id
FROM wsh
</CFQUERY>
<!--- When user submits form, save search criteria in Client variable --->
<CFIF IsDefined("Form.SearchCriteria"
<CFSET CLIENT.LastSearch = Form.SearchCriteria>
<!--- If not submitting yet, get prior search word (if possible) --->
<CFELSEIF IsDefined("CLIENT.LastSearch"
<CFSET SearchCriteria = CLIENT.LastSearch>
<!--- If no prior search criteria exists, just show empty string --->
<CFELSE>
<CFSET SearchCriteria = "">
</CFIF>
<CFSET PageStatus = "Search">
<CFFORM ACTION="#CGI.SCRIPT_NAME#" METHOD="Post" class="maintext">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="28%">
<!--- "Search Criteria" field --->
<span class="maintext2bold">Search</span>
<p> <span class="maintext2">Select a system to cross reference:<br>
</span>
<cfinput name="SearchCriteria" class="dropdown"> <cfoutput query="get_ws"
option value="#get_ws.system#"
#get_ws.system# </CFOUTPUT>
required="Yes"
message="Your query is blank - please enter a word or phrase.">
</td>
<td width="34%" align="right" valign="bottom">
<!--- "Submit" button --->
<input name="Submit" type="Submit" class="button" value="Search"></td>
</tr>
<tr>
<td colspan="4"><hr noshade></td>
</tr>
</table>
</CFFORM>
<!--- If we have something to search for, do it now --->
<CFIF SearchCriteria NEQ "">