Add Comment
Auto Save Form Tutorial
ColdFusion Tutorial #10
ColdFusion 8 cfform tag comes with javascript libraries that enable AJAX form submission. This example ties this in with some Javascript to autosave the form at a specified number ofmilliseconds.
demo.cfm
To fire off the autosave action the onLoad attribute of the body tag calls autoSaveEvery with an argument of milliseconds. This function calls the JavaScript function setTimeout which after the specified number of milliseconds will call autoSave. autoSave contains the ColdFusion.Ajax.submitform line and then calls autoSaveEvery to begin the cycle again.Thats it. The form can contain any elements either those created by cf (cfinput, cftextarea, etc) or straightforward html form.
autoSaveAction.cfm
Most likely the action page will save values to a database, possibly with a flag indicating its a draft, but for examples sake we will put them in a session variable.This just saves the form into a session variable.
autoSaveView.cfm
The view page just dumps the saved results from the session variable.Demo
See this code running!
Download
Download this code as a zip!
Comments
great examplePaul @ Saturday 29 Sep 2007 - 02:26:36 AM
Im trying out this demo but the array is always empty??
Joe Coree @ Friday 02 Nov 2007 - 09:04:22 PM
Not sure what happened here as this was working.
I've modified the code slightly and it is working again
Dale Fraser @ Friday 02 Nov 2007 - 09:35:56 PM
Thanks demo works now
But I still get an empty array on my dev version using the new action page
Joe Coree @ Friday 02 Nov 2007 - 10:04:08 PM
In order to use session variables - had to add an Application.cfm!
Joe Coree @ Friday 02 Nov 2007 - 11:05:44 PM
Thanks for the tutorial. Might be a good idea to link your blog to this site, if you haven't already done so.
Calvert @ Wednesday 07 May 2008 - 05:32:52 AM
Click button to add a comment
Author
Sam Farmer
Published
Thursday 27 Sep 2007Original
This tutorial has been modified and published with permission of the author. The original tutorial can be found herehttp://samfarmer.instantspot.com/blog/index.cfm/2007/8/27/ColdFusion-8-AutoSaving-with-cfAjaxProxy