Connecting Tech Pros Worldwide Forums | Help | Site Map

passing search form information

Newbie
 
Join Date: Mar 2007
Posts: 22
#1: Mar 13 '07
Hi Peoples
i have a search page with a form field "subject" on my results page i have a paging routine . the first page lists its 10 records no trouble but when i click the "next" link i get a error telling me "subject is not defined in form"
How can i overcome this please.
I will post the page down to the end of the paging routine coz its not very long anyway.


[HTML]<cfquery name="searchResults" datasource="#dsn#">
SELECT threadID, posttype, topic, topicID, postdate, username, threads.catID, posttext, categories.catID, category
FROM threads INNER JOIN categories
ON threads.catID=categories.catID
WHERE topic LIKE '#form.subject# %' OR topic LIKE '% #form.subject#' OR topic LIKE '% #form.subject# %' OR topic LIKE '#form.subject#'
OR username LIKE '#form.subject#'
OR posttext LIKE '#form.subject# %' OR posttext LIKE '% #form.subject#' OR posttext LIKE '% #form.subject# %' OR posttext LIKE '#form.subject#'
</cfquery>




<!---Set the number of entries (records) per page--->
<cfset perPage = 10>
<!--- Set the parameter "url.start" default to 1--->
<cfparam name="url.start" default="1">
<cfif not isNumeric(url.start) or url.start lt 1 or url.start gt searchresults.recordCount or round(url.start)
neq url.start>
<cfset url.start = 1>
</cfif>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<link href="CSStyle/forum.css" rel="stylesheet" type="text/css">
</head>

<body>



<div id="Layer2" style="position:absolute; left:0; top:0; width:30px; height:23px; z-index:6">
<cfinclude template="header.cfm">
</div>
<div id="Layer3" style="position:absolute; left:75px; top:190; width:850; height:83px; z-index:7">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<cfoutput>
<tr>
<td colspan="2"><span class="standard33">Your search for</span> <span class="standardred">'#form.subject#'</span> <span class="standard33">returned </span><span class="standardred">'#searchResults.RecordCount#'</span> <span class="standard33">results.</span></td>
<!---DISPLAY PAGE NAVIGATION BUTTONS---><!---DISPLAY PAGE NAVIGATION BUTTONS--->
<cfoutput>
<tr class="standard">
<td colspan="3" align="right">
<cfif url.start gt 1>
<cfset link = cgi.script_name & "?start=" & (url.start - perpage) & "&subject=" & "#subject#">
<span class="small11-33"><a href="#link#">&lt;&lt; Previous</a></span>
<img src="siteImages/navSeperator.gif" width="5" height="5">
</cfif>
<cfif (url.start + perpage - 1) lt searchresults.recordCount>
<cfset link = cgi.script_name & "?start=" & (url.start + perpage) & "&subject=" & "#subject#">
<span class="small11-33"><a href="#link#">Next &gt;&gt; </a></span>
</cfif>
</td>
</tr>
</cfoutput>
<!---END DISPLAY PAGE NAVIGATION BUTTONS--->[/HTML]

Cheers and thanks in advance
Grabit

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Mar 13 '07

re: passing search form information


The problem is that 'form' is for POST variables and you are trying to access form.subject without having posted the variable. The solution is to use url.subject and pass the form.subject value in the link, e.g
Expand|Select|Wrap|Line Numbers
  1. nextpage.cfm?subject=#form.subject#
Be sure to use cfparam to set a default in case someone comes along and alters the url. Normally, for searches, I just use the URL so that it's easy to support navigational previous/next links.
Reply