Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to keep form variable alive on requery page 2?

Status
Not open for further replies.

mmaddox

IS-IT--Management
May 22, 2002
53
US
Can anyone help with this problem?
Page one has a drop down where the user selects a Site.
Site is passed to page two where the selection is used in a SQL where clause. That works fine.
Page two has click to sort column heading which re-loads the page with Order By info. However, when the column sort is done, it loses the earlier Site selection variable value and returns an error:

page one:

<cfparam name="TheSite" default="">
<cfquery name="getSite" datasource="data">
Select distinct site
from tbldata
order by site
</cfquery>

<cfform name="selectSite" action="page2.cfm" >
<cfselect name="TheSite"
query="getsite"
value="site"
selected="#Thesite#">
</cfselect>
<input type="submit" name="" value="go" method="post">

</cfform>

page two (page2.cfm)

<cfparam name="sort" default="1">
<cfquery name="qrydetail" datasource="data">
SELECT hltag, name, site
FROM tbldata
WHERE site = '#form.TheSite#'
ORDER BY
<cfswitch expression="#sort#">

<cfcase value="1">hltag, name</cfcase>
<cfcase value="2">hltag DESC, name</cfcase>
<cfcase value="3">name</cfcase>
<cfcase value="4">name desc</cfcase>

</cfswitch>
</cfquery>


<cfoutput>
<tr bgcolor="##E5E5E5"><!--- header row --->
<td><a href="page2.cfm?sort=#IIF(sort is 1, '2', '1')#">hltag</a></td>
<td><a href="page2.cfm?sort=#IIF(sort is 3, '4', '3')#">name</a></td>
<td>site</td>
</tr>
</cfoutput>

<cfoutput query="qrydetail"><!--- data rows --->
<tr>
<td>#qrydetails.hltag#</td>
<td>#qrydetails.name#</td>
<td>#qrydetails.site#</td>

</tr>
</cfoutput>

ERROR: Element THESITE is undefined in FORM. - WHERE site = '#form.TheSite#'
 
Try this:

Code:
<td><a href="page2.cfm?sort=#IIF(sort is 1, '2', '1')#&thesite=#thesite#">hltag</a></td>
<td><a href="page2.cfm?sort=#IIF(sort is 3, '4', '3')#&thesite=#thesite#">name</a></td>
and
Code:
WHERE site = '#TheSite#'

Kris Brixon
www.brixon.org
 
Actually, dropping the scope is more of a hack than a solution. Using unscoped variables is bad coding practice and should be avoided.

You would be better off to keep the variable named "form.TheSite", and just check for the existance of the variable and have a cfparam tag if it's not there.
Code:
<cfif NOT IsDefined("form.TheSite">
  <cfif IsDefined("Url.TheSite")>
    <cfparam name="form.TheSite" default="#Url.TheSite#">
  <cfelse>
    <cfparam name="form.TheSite" default="N/A">
  </cfif>
</cfif>

.....

SELECT     hltag, name, site
FROM tbldata
WHERE site = '#form.TheSite#'

.....

<td><a href="page2.cfm?sort=#IIF(sort is 1, '2', '1')#&thesite=#Form.thesite#">hltag</a></td>

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Try this... I did not test it.... It will keep the site vairable from the form and put it in the urls of the sort headers, it checks to see if the form variable exists or the url variable exists.

Code:
<cfif structKeyExists(form,"theSite")>
	<cfset theSiteVar = form.thesite>
<cfelsif structKeyExists(url,"theSite")>
	<cfset theSiteVar = url.thesite>
<cfelse>

error, form.thesite nor url.thesite exists (your own error control, redirect back to the site selection page, etc... goes here)

</cfif>


<cfparam name="sort" default="1">
<cfquery name="qrydetail" datasource="data">
    SELECT     hltag, name, site
    FROM tbldata
    WHERE site = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#theSiteVar#">
    ORDER BY
    <cfswitch expression="#sort#">

        <cfcase value="1">hltag, name</cfcase>
        <cfcase value="2">hltag DESC, name</cfcase>
        <cfcase value="3">name</cfcase>
        <cfcase value="4">name desc</cfcase>
            
    </cfswitch>
</cfquery>


<cfoutput>
<tr bgcolor="##E5E5E5"><!--- header row --->
<td><a href="page2.cfm?sort=#IIF(sort is 1, '2', '1')#&theSite=#theSiteVar#">hltag</a></td>
<td><a href="page2.cfm?sort=#IIF(sort is 3, '4', '3')#&theSite=#theSiteVar#">name</a></td>
<td>site</td>
</tr>
</cfoutput>

<cfoutput query="qrydetail"><!--- data rows --->
<tr>
<td>#qrydetails.hltag#</td>
<td>#qrydetails.name#</td>
<td>#qrydetails.site#</td>

</tr>
</cfoutput>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top