Skip to main content
Participating Frequently
July 18, 2006
Question

Set session variables inside a page

  • July 18, 2006
  • 4 replies
  • 834 views
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 has been closed for replies.

    4 replies

    Inspiring
    July 19, 2006
    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.

    Inspiring
    July 18, 2006
    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?
    cfworkAuthor
    Participating Frequently
    July 19, 2006
    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


    cfworkAuthor
    Participating Frequently
    July 18, 2006
    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
    Inspiring
    July 18, 2006
    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.
    Inspiring
    July 18, 2006
    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