I saw something that looked cool in Hal Helm's newsletter and wanted to try it out. He placed a form structure into session scope. It works fine when I put it in but when I return to the page the form data is no longer in the session scope. <cfset session.previousFormValues = form /> Code (markup): The rest of the page has a simple form and some CFDUMPS. Other variables stay in the scope but the form structure does not stay. Any thoughts are appreciated.
Interesting idea...I can think of many possible uses! I assume you have session variables enabled in your application, you are locking session vars, etc.?
Sessions are enabled, I put CFLOCK in place but it isn't really necessary since I am the only user at the moment. I can create an array, say myarray, and set it as session.myarray and it sticks but the form structure doesn't stay in the session scope. I think I'll create my own struct and put it in the array and see if it stays.
Yes this is good, it's sort of like putting a function in the session-scope as well. Here are few things: 1) Check your logs (if you can) or 2) Try using StructInsert HTH daTropics
Nothing in the logs when I add form data to session scope and return. The session scope will retain an array or struct that I create but it won't retain the form data I pass in.
Make sure on the initial page load of the form that you are not redefining the session = form variable. If you are that means it is working, its just resetting the variables due to your logic and the fact that the Form vars currently contain no data.
you could copy the form structure to a session variable using something like structcopy. Make sure you lock/unlock correctly though.
That's because structures are copied by reference. The variable session.previousFormValues only stores a reference to FORM. So anything that happens to FORM also happens to your session variable. If you visit another page where the FORM structure is empty, your session.previousFormValues will also be empty because you're only storing a reference to the FORM structure. So newbish is right. You need to make a copy of the structure with either StructCopy or Duplicate. Generally, Duplicate is safer because it makes a deep copy of nested structures. <cfset session.previousFormValues = Duplicate(form) /> Code (markup):