Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Passing variables

New Here ,
May 21, 2025 May 21, 2025

I inherited a Club website and a copy of CF for Dummies. All went well until my ISP upgraded. Now I can't pass variables between pages. What to do?

329
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 24, 2025 May 24, 2025

Let's take your previous example:

 

Testsend.cfm

<html>

<head><!--- Nothing ---></head>
 <body><cfoutput><a href = "testreceive.cfm?varmy=10">Click</a></cfoutput></body>
</html>

Testreceive.cfm

<html>
<head> <!--- Nothing ---></head>
<body><cfoutput>Received variable: #varmy#<br></cfoutput></body>
</html>

 

Since varmy is a URL variable, that is, one that comes in through the query string, you should "scope" it as follows: 

<body><cfoutput>Received variable: #url.varmy#<br></cfoutput></body>

 

Yes, th

...
Translate
Community Expert ,
May 22, 2025 May 22, 2025

What to do depends on your code. For some code, you don't even have to pass variables between pages. 

 

If you shared the code, you would certainly get suggestions on how to solve the problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 22, 2025 May 22, 2025

Like @BKBK recommended, you should definitely share your code. In addition to that, you should provide some additional details. What got upgraded exactly? What errors are you seeing? What version of CF is covered by your book? Basically, any information you can provide may help us help you.

 

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2025 May 23, 2025

The original code called on javascript to display a larger version of a small (width-180) picture in a gallery of several lines of 4 pictures per line. The larger version would close after a number of seconds passed as a second variable.

This works on my home set-up and used to work at my ISP.

Having hit a brick wall with the new set-up at my ISP, I removed the javascript and added a “Close” button to the larger picture to return to the gallery. Not ideal.

This is within two loops for the number of lines in the gallery and a 1 to 4 loop for pictures per line

<td valign = top><p align = "center">#a_title[jk]#</p><a href = "windowpics.cfm?tramp=#jk#"><img src="gallery/#a_pic[jk]#.jpg" width = 180></a></td>

This works in my home set-up, but when showing windowpics.cfm,  the ISP delivers “Variable TRAMP is undefined”

My next attempt was to write two minimalist programs without any CF code

Testsend.cfm

<html>

<head><!--- Nothing ---></head>
 <body><cfoutput><a href = "testreceive.cfm?varmy=10">Click</a></cfoutput></body>
</html>

Testreceive.cfm

<html>
<head> <!--- Nothing ---></head>
<body><cfoutput>Received variable: #varmy#<br></cfoutput></body>
</html>

This works at home but  gives “Variable VARMY is undefined”.when trying to run testreceive.cfm

My home set-up is whatever Adobe was offering in 2015. The ISP has gone to Version 2021 which does not support MsAccess – which is a whole new set of problems.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2025 May 23, 2025

I am assuming you are on ColdFusion 2023. Then my guess is that the issue is caused by a change in the language, starting from Update 7 of ColdFusion 2023.

 

Up until then, if you defined a variable, myVar, without specifying the scope, ColdFusion would automatically look for myVar in every relevant scope. 

 

That behaviour has been changed. From Update 7 onwards, you must explicitly state the intended scope of each variable, for example, 

url.varmy

Otherwise, you get an error.

 

However, there is an alternative. If you want ColdFusion to revert to its old, pre-Update-7 behaviour (that is, automatically search for a variable across every relevant scope), then you will have to proceed as follows:

  1.  Add the flag -Dcoldfusion.searchimplicitscopes=true to the JVM arguments, then restart ColdFusion;
    Alternatively,
  2.  Define the following in Application.cfc:
    <cfset this.searchimplicitscopes=true>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2025 May 23, 2025

Do you need assistance with "JVM arguments" or with "Application.cfc"? Then the forum can help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2025 May 24, 2025

Until now I have never had to deal with scopes. I was able to pass variables between templates by using

<a href="nextpage.cfm?varmy=#xyz#">Click</a> or in the "Action" section of a form. What kind of scope do I now need to pass a variable between templates? How and where do I define the scope? 

Using 

<cfset this.searchimplicitscopes=true>

is tempting, but the documentation says it will soon disappear.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2025 May 24, 2025

Let's take your previous example:

 

Testsend.cfm

<html>

<head><!--- Nothing ---></head>
 <body><cfoutput><a href = "testreceive.cfm?varmy=10">Click</a></cfoutput></body>
</html>

Testreceive.cfm

<html>
<head> <!--- Nothing ---></head>
<body><cfoutput>Received variable: #varmy#<br></cfoutput></body>
</html>

 

Since varmy is a URL variable, that is, one that comes in through the query string, you should "scope" it as follows: 

<body><cfoutput>Received variable: #url.varmy#<br></cfoutput></body>

 

Yes, the documentation says there will be no searchImplicitScopes flag from ColdFusion 2025 onwards. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2025 May 24, 2025

Thanks - youv'e made my day!

J

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2025 May 25, 2025

Guys, while it's great that judo has solved the problem with hard-coding the scope, let's clarify about solving it otherwise.

 

First, despite what the docs say, the jvm arg IS in fact supported in cf2025. Adobe reversed their plans after that March 2024 update that introduced this. (FWIW, they did not reverse their removal in cf2025 of the similar cfmx_compat arg that came out with the Apr 2024 update.) 

 

Second, though, note that the ability to control this at the app level (setting searchimplicitscope in cfapplication or in an application.cfc) was NOT indicated to be removed at all. It was only the jvm arg approach--which has been reversed for now. 

 

All that said, there's certainly a security argument for correcting code rather than app or jvm level settings. 

 


/Charlie (troubleshooter, carehart. org)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2025 May 25, 2025
LATEST
quote

Thanks - youv'e made my day!

J


By @judo1

 

My pleasure.

 

Should you be looking for a way to use Application.cfc to free you from having to add the "url" scope, here is a tip.

Store the following code as Application.cfc in the same directory as the CFM files.

<cfcomponent>

    <!--- Application settings --->
    <cfset this.name = "MyTestApp">
    <cfset this.sessionManagement = true>
    <cfset this.sessionTimeout = createTimeSpan(0, 0, 20, 0)> 
    <cfset this.applicationTimeout = createTimeSpan(1, 0, 0, 0)> 
    <cfset this.searchImplicitScopes = true>
    
    <!--- Called when the application is first initialized --->
    <cffunction name="onApplicationStart" returnType="boolean">
       
        <cfreturn true>
    </cffunction>

    <!--- Called when a session starts --->
    <cffunction name="onSessionStart" returnType="void">
        
    </cffunction>

    <!--- Called for every request --->
    <cffunction name="onRequestStart" returnType="boolean">
        <cfargument name="targetPage" type="string" required="true">

        <cfreturn true>
    </cffunction>

</cfcomponent>

 

With Application.cfc in place, you can now use the following code as before:

<!--- Specifying the "url" scope is now optional. However, it is recommended to do so. --->
<body><cfoutput>Received variable: #varmy#<br></cfoutput></body>

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources