Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Coldfusion session or client variables won't save or pass between pages and reset to undefined

Posted on 2006-07-08
5
Medium Priority
?
397 Views
Last Modified: 2013-12-24
I have spent hours searching the PAQs and haven't found a solution.  This is driving me crazy!  I'm extremely pressed for time and a solution, and need help right away!

I have a CFM form page, let's call it form.cfm, which submits to another CFM "processing" page, and let's call this page "post_signup.cfm".

The situation I'm attempting to get around is is that on the post_signup.cfm page I have a <cfmail> statement which sends the form data off via e-mail (as well as the data being posted to a SQL database), but if the user hits the REFRESH button while on the post_signup.CFM page, the data is resubmitted and re-emailed.  I've also tried "expire" the page with the no-cache meta commands in the hopes that the form.submit (submit button) status would revert to undefined.

I tried setting up the following on the post_signup.cfm page:

<cfif  NOT IsDefined('form.submit')><cflocation url="form.cfm"></cfif>  <!--- if the submit button from the form.cfm wasn't the way the came in, redirect them over to the form.cfm page --->

<cfif NOT isDefined('session.dataposted')>  <!--- Check to see if session variable is defined in the first place before attempting to assign values --->
<cfset session.dataposted=0>  <!--- Set the dataposted session variable to 0 for the first time the data is displayed --->
</cfif>

<cfif (session.dataposted EQ 1)> <!--- Check to see if we've been here before --->
<cfset session.dataposted=0> <!--- Reset the session variable back to 0 since it's SUPPOSED to  be a persistent var in case the user posts more data later --->
<cflocation url="index.cfm">   <!--- Go back to the home page --->
<cfelse>
<cfset session.dataposted=1>  <!--- Set the dataposted session variable so when/if the page is refreshed, the cfif above will redirect --->
</cfif>

The problem is that the session.dataposted variable is "undefined" each time the page is refreshed, so it's always set to 0.  (I check it with a CFOUTPUT of it's value further down the page).

I need to be able to show the data that was submitted while users view the post_signup.cfm page, so I can't have the page posting/emailing the data and redirecting to another page that doesn't show the FORM data.

If I try to predefine the session variable on the form.cfm page or even in the Application.cfm, then try to change it's value on the post_signup.cfm, the value is not stored, and when the page is refreshed the session.dataposted variable always has whatever it's initial value was.

My Application.cfm has session variables set to expire within 20 minutes and both sessionmanagement and  clientmanagement = Yes. (Not using client-side cookies in case user has them disabled in their browser).

I have even gone so far as testing a couple of pages with a Client.testvar variable instead of using session variables (but I'd really like to have both work):
page1.cfm:
<body>
<cfif not isDefined('Client.testvar')>
<cfset #Client.testvar# = "TESTING">
</cfif>

This is a test <CFOUTPUT>#Client.testvar#</CFOUTPUT>
<a href="test1a.cfm" target="_self">test 1a</a>
/body>

page1a.cfm:
<body>
<cfif not isDefined('Client.testvar')>
<cfset Client.testvar = "TESTING2">
</cfif>

This is a test <CFOUTPUT>#Client.testvar#</CFOUTPUT>
<a href="test1.cfm" target="_self">test 1a</a>
</body>

Because the Client.testvar is defined on page1.cfm, should I see it still set to "TESTING" on page1a.cfm?  page1a.cfm thinks that it's not defined, and defines it to be "TESTING2" and when clicking to go back to page1.cfm, it is reset again.

PLEASE HELP QUICKLY!  THANK YOU!
0
Comment
Question by:vitoasaro
  • 3
  • 2
5 Comments
 
LVL 36

Expert Comment

by:SidFishes
ID: 17065450
"I need to be able to show the data that was submitted while users view the post_signup.cfm page, so I can't have the page posting/emailing the data and redirecting to another page that doesn't show the FORM data."

why not just pass the form data to the redirect page


submit.cfm
===============
<cfquery ....insert
<cfmail...

<cflock scope="Session" type="exclusive" timeout="20">
<cfset session.formfield1 = Form.somefield>
<cfset session.formfield2 = Form.someotherfield>
</cflock>

<cflocation url="post_signup.cfm">
==============

post_Signup.cfm
==============
<cflock scope="Session" type="readonly" timeout="20">
<cfset varformfield1 = session.somefield>
<cfset varformfield2 = session.someotherfield>
</cflock>

Thanks for signing up.
You submitted #varformfield1# and #varformfield2#



0
 
LVL 36

Expert Comment

by:SidFishes
ID: 17065458
of course you should also just do a check prior to the insert

submit.cfm
===============

<cfquery name="eCheck" ...>

select emailaddy from mytable where emailaddy = '#form.emailaddy#'
</cfquery>

<cfif eCheck.recordcount Neq 0> <!--- then we've got a match --->

Oops...already registered
Click to go somewhere else

<cfelse>

<cfquery ....insert
<cfmail...

<cflock scope="Session" type="exclusive" timeout="20">
<cfset session.formfield1 = Form.somefield>
<cfset session.formfield2 = Form.someotherfield>
</cflock>

<cflocation url="post_signup.cfm">
</cfif>


==============
0
 

Author Comment

by:vitoasaro
ID: 17065560
Thanks for the quick reply, SidFishes.

The problem is that the session variables don't seem to be maintained across pages, so your example:

<cflock scope="Session" type="exclusive" timeout="20">
<cfset session.formfield1 = Form.somefield>
<cfset session.formfield2 = Form.someotherfield>
</cflock>

would appear to set those session variables on that page, but then when I jump to another page and attempt to output those variables in a <cfoutput></cfoutput> block, I'll get an error stating that those variables are undefined in the session.  Same happens if I use client variables.  So, for example, setting the variables as you show above, then linking to another page where I have:

<cflock scope="Session" type="exclusive" timeout="20">
<cfoutput>
Values of variables that should be set: #session.formfield1# #session.formfield2#
</cfoutput>
</cflock>

would prodcuce the error "formfield1 is undefined in SESSION"
0
 
LVL 36

Accepted Solution

by:
SidFishes earned 1500 total points
ID: 17065598

Do you have session mgmt turned on in application.cfm?

<CFAPPLICATION NAME="YOurApp" sessionmanagement="YES" clientmanagement="yes" setclientcookies="YES">
0
 

Author Comment

by:vitoasaro
ID: 17065782
SidFishes:

Yes, I do have session mgmt turned on.

Another friend helped steer me in the right direction as well as your last question...  The URLToken wasn't consistently being passed along, so when I finally paused to look at the URL I noticed that part of it was missing.

Making sure that the addtoken="yes" was in all of my <cflocation> tags, and that all of my <FORM> and <CFFORM> tags were set up such as:
<CFFORM action="action.cfm?#Client.URLToken#" method="post"> were most important because the session state wasn't being maintained in the URL.

In some cases I had <CFFORM action="action.cfm?#Client.CFID#" method="post"> or didn't have it all, so without a reference to these session state variables, the server had no way of knowing that I was the same client (browser) trying to access my client/session variables.

Thanks again for the assist!
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question