Skip to main content
Participating Frequently
Jul 18, 2006 2:33 PM UTC
Question

Set session variables inside a page

Inside the page "form.cfm" I have this code:


<form name="report" action="pagestatistic.cfm" method="post">

<INPUT name=ONE size=15 >

<INPUT name=TWO size=15 >

<input type="submit" value="Go ON">

</form>


I would like to set session variable: ONE and TWO, inside the page: pagestatistic.cfm

IN that way when I will refresh the page "pagestatistic.cfm" I will watch have the same results.

I added this code at the top of "pagestatistic.cfm" but it doesn't work.

<CFSET session.ONE = #ONE#>
<CFSET session.TWO = #TWO#>


Could you tell me what goes wrong?

Thanks

CFWork
    This topic is closed to new replies. Start a new post to keep the conversation going.

    7 replies

    Inspiring
    Jul 19, 2006 7:46 PM UTC
    Well, without using some javascript, you cant edit your links destination without submitting the form via a submit button. You can have it submit directly to the same page. Make sure that you set defaults for any variables first like this:
    <cfparam name="ColorPage" default="Green">

    Then after they submit the form, you will have access to the variables from the form: form.ColorPage.

    Translate
    Inspiring
    Jul 18, 2006 4:59 PM UTC
    When you say refresh the page, do you mean submit the form by clicking on the submit button? Or are you filling out the input boxes and hitting refresh?
    Translate
    cfworkAuthor
    Participating Frequently
    Jul 19, 2006 8:50 AM UTC
    quote:

    Originally posted by: liquid One
    When you say refresh the page, do you mean submit the form by clicking on the submit button? Or are you filling out the input boxes and hitting refresh?


    I mean I clicked a link that links the same page: pagestatistic.cfm

    Then I would like to add to this link 2 get variables pagestatistic.cfm?ColorPage=Green&Order=2 to change the background color and the order of the results of the page. That it is impossible because when i refresh the page it is doesn't work.

    What do you suggest me to do?


    Thanks,

    CfWork


    Translate
    cfworkAuthor
    Participating Frequently
    Jul 18, 2006 3:36 PM UTC
    Unfortunatly it doesn't work.
    When I refresh the page I obtaind this response.


    Error Diagnostic Information

    An error occurred while evaluating the expression:

    session.ONE = form.ONE

    Error near line 1, column 7

    Error resolving parameter FORM.ONE

    The specified form field cannot be found. This problem is very likely due to the fact that you have misspelled the form field name.


    CfWork
    Translate
    Inspiring
    Jul 18, 2006 3:42 PM UTC
    is there any other code on your page???? i setup a page just like yours and used your code and it works just fine for me.
    Translate
    Inspiring
    Jul 18, 2006 2:41 PM UTC
    How do you know its not working? Are you getting an error? Also, typically when you start naming variables the same you may want to scope them.

    <cfset session.one = form.one />

    You don't need the pound signs inside of a cf tag unless the variable is in single or double quotes.
    You can also turn on debugging to see if they are set as well
    Translate