Solved

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

Posted on 2006-07-08
5
355 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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Blue Coat API portal URL 2 163
assigning port numbers to web sites and web services 2 75
whm high memory usage in processes 7 88
Domino Website - Redirection 12 76
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

770 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