Skip to main content
Inspiring
June 10, 2007
Question

auto save every 15 minutes

  • June 10, 2007
  • 8 replies
  • 2448 views
i have built an application for a client which has large forms that some users take a long time to fill out. so long that often the session will time-out while they are working on it. the session is set to time out after an hour and the client understands this and does not want to change this but they would like to make it so that the form they are working with saves its data every 15 minutes so that if the session times out they ust log back i and the data they entered in the form is not lost.

how could i accomplish somethinglike this?
    This topic has been closed for replies.

    8 replies

    Inspiring
    June 13, 2007
    I don't remember if this was mentioned in this thread or not, but you can use WDDX to serialize your form data and pass it back & forth between javascript and CF using AJAX.
    Inspiring
    June 12, 2007
    Personally, I don't think this is the best solution, but I figure I'd mention it:

    You could always put in a hack to prevent the browser from timing out on that page. Use a frameset or an iframe along with a bit of javascript that requests/refreshes itself every 14 minutes or so. Should prevent a time out.
    BKBK
    Community Expert
    Community Expert
    June 13, 2007
    Here is a tiny working example. Create 2 DB tables formData_temp and formData_final. Each has columns dt [datetime], sometext[varchar(50)] and id[varchar(35)]. The column id is the primary key. I used createUUID() to prepopulate formData_temp's id column. All other column entries are null. The table formData_final is empty when we start.

    Requirement:
    - Javascript is running on the client
    - cfform, so that you can make use of the preserveData attribute
    - the action page is the form page itself



    added edit:
    1) onclick="document.myForm.submissionType.value='final';"
    2) data type added



    bdee2Author
    Inspiring
    June 13, 2007
    that may be just what i was looking for - my page is a bit more complex so you will have to add some things to your code but the basic principle behind it should do the trick. i will give it a shot hopefully this weekend.
    June 12, 2007
    Cookies are your best bet when sharing information between Javascript and CF - I think. Both languages can read cookies. Set whatever you want in the cookie and get CF to read it.
    bdee2Author
    Inspiring
    June 12, 2007
    gotcha - thanks!
    BKBK
    Community Expert
    Community Expert
    June 11, 2007
    Kapitaine wrote:
    Couldn't you utilise the "onSessionEnd" feature of the Application.cfc?

    Bdee2 wrote:
    - it would be better if it [could] just save the form data silently every fifteen minutes. or better yet - save the form data when the session times out.

    We should not forget the usual state of affairs. While the user is filling the form the Coldfusion server and the browser are not interacting. Therefore, the browser will not be aware of any decision that the server makes, be it before or after the session ends. You will find it more difficult to think up a server-side solution to the problem than a client-side one.


    bdee2Author
    Inspiring
    June 11, 2007
    yea thats a good point - so since the page is not interacting with the server, the page will have no way of knowing when the session ends. perhaps i could have a javascript that starts a timer when the page loads and every 15 minutes it writes the values of the fields out o a cookie and then refreshed the timer. would that be feasible? if so how could i accomplish something like that?
    Participating Frequently
    June 11, 2007
    If you're into object-oriented programming, set a form bean in session to store the data that will be submitted through the form. If not, then place a struct variable in session to do the same thing.

    Once you've decided which session variable you'll use, you can save the current form values to them using Ajax and a time-based script. AjaxCFC is one of the best ways to hook CF and Ajax together. Once you get started, things will progress pretty quick.

    Since these session variables will be updated regularly, say every 5 minutes, the session timeout should be refreshed with each save. Should the user close the browser without logging out, their session will still be active. You could then use onSessionEnd() to save any existing form-content session variables to the database so the user can pick up their unfinished form later.
    June 11, 2007
    June 11, 2007
    For reference...

    onApplicationEnd
    onApplicationStart
    onError
    onRequest
    onRequestStart
    onRequestEnd
    onRequestStart
    onSessionEnd
    onSessionStart

    http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000692.htm
    June 11, 2007
    Couldn't you utilise the "onSessionEnd" feature of the Application.cfc? I'm not an expert with sessions but it sounds like the logical thing to do.

    You may be able to catch any expiring sessions in there and do something.

    Hope this helps.

    Cheers.
    bdee2Author
    Inspiring
    June 11, 2007
    ye i had thought about using onSessionEnd but i didn't think i would be able to access the session at that point. i always thought that when the onsessionend was triggered, the session variables had already been killed.
    BKBK
    Community Expert
    Community Expert
    June 10, 2007
    You could write a Javascript scriptlet to notify the client every 15 minutes to save the current data.

    bdee2Author
    Inspiring
    June 11, 2007
    i think that would prbaly annoy the user - it would be better if it coudl just save the form data silently every fifteen minutes. or better yet - save the form data when the session times out.