14 July 2006

Copying form scope into session scope CFMX 7

I've just noticed a weird behaviour with the form scope in CFMX 7. I was trying to copy all the data in the form to a session variable e.g.

Session.formData = StructNew()
Session.formData = form

Do a <cfdump var="#session#"> immediately after that line and you see the form structure inside the session structure. However, I noticed that when I redirect onto another page without form scope, the Session.formData structure was empty - it didn't persist, even though it was copied to the Session scope!?

What must be happening is that a reference to the form scope is copied into the Session NOT the form data. When you move to another page where the form scope does not exist, then the data is not in the Session.

You must loop though form.fieldnames and set the data explicitly, like so:
<cfloop list="#form.fieldnames#" index="item">
<cfset Session.formData[item] = Evaluate(item) />
</cfloop>


I should try and remember to start posting more!

No comments: