#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Baltimore, MD
    Posts
    12
    Rep Power
    0

    Angry 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
  2. #2
  3. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,186
    Rep Power
    2265
    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.
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Baltimore, MD
    Posts
    12
    Rep Power
    0

    Code


    <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
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,264
    Rep Power
    968
    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.

IMN logo majestic logo threadwatch logo seochat tools logo