Skip to main content
judo1
Participating Frequently
May 21, 2025
Answered

Passing variables

  • May 21, 2025
  • 3 replies
  • 699 views

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?

    Correct answer BKBK

    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.


    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. 

    3 replies

    judo1
    judo1Author
    Participating Frequently
    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.

    BKBK
    Community Expert
    Community Expert
    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>
    BKBK
    Community Expert
    Community Expert
    May 23, 2025

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

    Community Expert
    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
    BKBK
    Community Expert
    Community Expert
    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.