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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirects

Status
Not open for further replies.

RikForgo

Programmer
Jul 31, 2002
59
US
I have a several different search/results page that contain multiple lists with dynamic URL links to different related detail pages. When the user gets to one of the detail pages, I want to provide a customized URL to return them to the list page where they started.

I have a general idea about how to do this, but my implementation isn't working. Here's what I've got.

1. Each list page sets a variable that identifies itself as the originating page with a CFPARAM tag (I placed this at the top of the list page):

<cfparam name=&quot;crossref&quot; default=&quot;tid&quot;>

2. Then I inserted the variable in the URL link between two CFOUTPUT tags:

<CFOUTPUT>
<TR VALIGN=&quot;baseline&quot;>
<TD colspan=&quot;3&quot; CLASS=&quot;#Class#&quot; > <span class=&quot;maintext2&quot;><a href=&quot;../wsh/cr_wsh_detail_01.cfm?id=#id#&wsh_year=#wsh_year#&crossref=#tid#&quot;><font color=&quot;##000099&quot;>#system# (#wsh_year#)</font></a></span> <div align=&quot;left&quot;></div>
<div align=&quot;left&quot;></div></TD>
</TR></CFOUTPUT>

I'm not sure if it works on the detail page because I can't get out of the list page. It fails on the URL in Step 2. The error I get is below. The error says I haven't named the query attribute, but this wasn't a query. Any help is appreciated.


An error occurred while evaluating the expression:

#tid#

Error near line 155, column 143.
---------------------------------------

Error resolving parameter TID

ColdFusion was unable to determine the value of the parameter. This problem is very likely due to the fact that either:

You have misspelled the parameter name, or
You have not specified a QUERY attribute for a CFOUTPUT, CFMAIL, or CFTABLE tag.

The error occurred while processing an element with a general identifier of (#tid#), occupying document position (155:142) to (155:146) in the template file
 
When you get that error, it means that the variable doesn't currently exist in the variables scope (are whatever scope you're implying).

Without seeing the rest of your code, I'd have a hard time determining why it doesn't exist, but it doesn't.

I'm not sure if the CFPARAM you mentioned is supposed to be connected to the process somehow, but right now it doesn't seem to be.

With
Code:
<cfparam name=&quot;crossref&quot; default=&quot;tid&quot;>
you're ensuring that the variable named &quot;crossref&quot; is at least set to the literal string &quot;tid&quot;. Which if I had to guess, isn't really want you want. Unless the literal string &quot;tid&quot; means something to you. I'm imagining you mean
Code:
<cfparam name=&quot;crossref&quot; default=&quot;#tid#&quot;>
where the variables.crossref is at least set to the value of variables.tid. But we already know that the variable.tid doesn't exist... so I'm not sure what to suggest there.

Also, your link doesn't seem to make use of variable.crossref, so I'm not sure what the CFPARAM is really supposed to do. Perhaps you meant
Code:
<a href=&quot;../wsh/cr_wsh_detail_01.cfm?id=#id#&wsh_year=#wsh_year#&crossref=
Code:
#crossref#
Code:
&quot;>
?




-Carl
 
Thanks Carl,

You caught the error in a couple places. First I changed the <cfparam name=&quot;crossref&quot; default=&quot;tid&quot;> to <CFSET crossref=&quot;tid&quot;> so there would be a value associated with the tid variable. Then I changed the crossref=#tid# to crossref=#crossref#, and the page processes as it should.

Do you know of any inherent problems with using CFSET this way?
 
Other than the fact that Variables.crossref will always equal &quot;tid&quot;, no.

If that's your intended result, then that's just fine.

The advantage of CFPARAM is it checks whether the variable is already set and will only overwrite it (with the default value) if it is not.

Imagine something like:

mytest.cfm-
Code:
<HTML>
<HEAD>
<TITLE>My Test</TITLE>
</HEAD>
<BODY>
<CFPARAM name=&quot;URL.myvar&quot; value=&quot;none&quot;>
<CFOUTPUT>#URL.myvar#</CFOUTPUT>
</BODY>

If you called the above with
Code:
mytest.cfm?myvar=hello
, CFPARAM would recognize that myvar was being passed in on the query string (setting the variable URL.myvar) and would not overwrite it. The result of the page would be
Code:
hello

But if you called the above with
Code:
mytest.cfm
, CFPARAM would recognize that URL.myvar was not yet set, and would then set it to the value specified as the default. So the resulting page would be
Code:
none

If you were to do the same thing, with the CFPARAM not there, you would get an error as the CFOUTPUT tried to address a variable that didn't exist.


Now your alternative of:
mytest2.cfm-
Code:
<HTML>
<HEAD>
<TITLE>My Test</TITLE>
</HEAD>
<BODY>
<CFSET URL.myvar=&quot;none&quot;>
<CFOUTPUT>#URL.myvar#</CFOUTPUT>
</BODY>

the resulting page will always be
Code:
none
no matter what you actually pass in as a query string.

If that's what you want, then CFSET is certainly the right choice.

-Carl
 
OK, I understand. Tried it out, and it works great. Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top