Helpful Information
 
 
Category: ColdFusion Development
Data persistance in Cold Fusion

I have 5 pages taking employee information as input (Personal data, Education, Working Exp, Projects, Skills etc) I am using javascript for client side validation and Cold Fusion on the server side. I want to persist data from first to last form so that at end of submission user can verify the data from all 5 pages , then it will be posted in the data base. Please help!!! Thanks:(

You could write the filled-out data to <input type=hidden> tags on each subsequent page of the form... that way, all of the data stays until you're ready to submit to the DB.

Alternately, you could write the data to the database in sections, but you would need to determine which user was writing to which part of the DB as you went along. I'm sure CFML has a 'session' ID similar to that of PHP that you could use to link the 2 for this purpose.

<input type=hidden> tag is not an option here since I have about 100 questions and 5 pages to post. I was thinking about using session variables, but never built anything using session variable from scratch. SO if someone can send me a code example on how to use session variable I would appretiate it!
Thanks

Using session variables in CF is absurdly easy.

First, make sure you put a <cfapplication> somewhere that will run on each request, most likely the Application.cfm file. Something like this:

<cfapplication name="myAppName" sessionmanagement="Yes">

Then, when you want to set a session variable, you do:

<cfset session.myVar = "whatever">

To read it, you do:

#session.myVar#

That's it.

The only other thing to note is that if you plan on a decent load on the server, you should use <cflock> to lock reads and writes to session variables. Since they are memory-resident, you must avoid memory contention by locking if you expect a heavier load. But this is not required (it is recommended though).

Example:

<cflock timeout="" throwontimeout="No" name="#createUUID()#" type="EXCLUSIVE">
<cfset session.myVar = "whatever">
</cflock>

<cflock timeout="" throwontimeout="No" name="#createUUID()#" type="READONLY">
<cfset someLocalVar = session.myVar>
</cflock>

A well thought out application will minimize the need for locking by locking once at the start of the request to copy the session vars into the local scope, and then at the end of the request copy them back into the session scope.










privacy (GDPR)