Skip to main content
November 30, 2009
Question

Another newbie question: Passing variables

  • November 30, 2009
  • 2 replies
  • 1408 views

Sorry to ask such a basic question, but how do I pass a value (not input by user) from one page to another?

For example, I am creating a CMS set of pages. The first page lists all the tables I have in the datasource

eg

  • Tutorials
  • Menus
  • Knowledgebase

etc

When I click on one of the choices, I want to link to a form that then lists the current contents of that table - so the conditional syntax on the action page might be

if <passed variable>="tutorials" then

          CFQuery....

               select * from TutorialTable

     elseif <passed variable>="menus" then

          CFQuery,#...

               select * from Menustable

end if

etc etc

Any ideas?

Many Thanks

    This topic has been closed for replies.

    2 replies

    ilssac
    Inspiring
    November 30, 2009

    You should read up about ColdFusion's variable scopes.  ColdFusion offers quite a collection of scopes each having it's purpose and use.

    SERVER

    APPLICATION

    CLIENT

    SESSION

    REQUEST

    FORM

    URL

    VARIABLES

    ATTRIBUTES

    ARGUMENTS

    CALLER

    etc

    As mentioned by Dan, Session is the one you probably want to use for this case.

    November 30, 2009

    Thanks Ian & Dan,

    I have now read up about session variables so I have created the "application.cfm" page, saved it in my

    root folder and set "sessionmanagement" to "yes".

    However, I'm still struggling to work out at what point I set the variable's value.

    I mean, in this line of code, how do I set my variable (<CFSET SESSION.TABLECHOICE="xxxx">)

    <li><a href="/insert_form.cfm">SpryTest</a></li>

    Once the user has clicked on the link, he/she is already in the next webpage, so I guess

    I need to set the session variable before they click. But if I just put the CFSET code

    on the line previous, how to I make it apply to the relevant choice in the unordered list?

    ilssac
    Inspiring
    November 30, 2009

    Now you need to get a clear picture in your head on how a web application works and what code runs where when.

    It is important to clearly understand that you are dealing with two completely different systems that have a set of rules on how they talk to each other.  The server and the client.

    The basic flow if any ColdFusion applicaiton is:

    1) CFML code runs on the server and generates HTML/javascript code and gives the HTML code to the web server

    2) The web server sends the HTML/javascript code to the client.

    3) The client runs the HTML/Javascript code any user interaction that creates a new request is sent to the web server.

    4) If the web server receives a request for another CFML page, it hands the request off to ColdFusion and this cycle starts again.

    Your question sounds like you are expecting the Client and the Server to be running at the same time, and that just is not how this works.

    Inspiring
    November 30, 2009

    Use session variables.  Then you don't have to pass anything from page to page.