Save Form
Definition:
NDLLibrary.saveForm(ndlParams)
Description:
Save the current state of the form, allowing a user to reload the form and return to their previous position later without losing information already entered.
Parameters:
saveForm requires the following two properties to be added to the default ndlParams object:
ndlParams.Id - Required
A unique ID to identify the saved data.
ndlParams.SaveType - Optional
Specifies where you want the form to be saved:
"database" | Form data is saved to a database. This is the default value if this property is not supplied. |
"cookie" | Form data is saved to a cookie on the user's local machine. This cookie has a lifetime of 1 day. |
"local" | Form data is stored to local HTML5 storage, if supported by the user's browser. |
Returns:
nothing
Code Sample:
Example using a button's Clicked property to save the form, generate an ID using the current date and time combined with a randomly generated number and create a cookie to store the ID:
function<pageName>_<elementName>_clicked(ndlParams)
{
// Get today's date, and use that as part of the ID
var date=new Date();
var id=date.toISOString();
// Add a random number between 0 and 1000 to the end of the date (to ensure it's random)
id =id + Math.floor(Math.random() * 1000);
// Create a cookie to store our ID (the last parameter, 30, specifies the number
// of expiry days and can be changed to a different value if preferred)
NDLLibrary.setCookie("ndlSaveID",id,30);
ndlParams.Id =id;
return NDLLibrary.saveForm(ndlParams);
}
-
This code uses the same name for all cookies so you should modify this JavaScript where users could share a browser, otherwise one user could potentially retrieve the data saved by a previous user.
Notes:
-
Within your code, you will need to create a unique ID to identify the saved form and enter this into the ndlParams.Id property before calling the function. We suggest you save the ID to a cookie on the user's machine to allow it to be easily retrieved when a user wishes to restore their form.
-
This function uses the default ndlParams object because it requires the scope property contained in the default object. If you want to include this function within your own custom JavaScript, you will need to generate a JavaScript function from an Element's properties in order to obtain the default ndlParams and then modify that function or make its default ndlParams object available to other functions that you write.
-
If you are using cookies, you will need to display an appropriate warning message within the form and allow users to refuse the use of cookies.
-
If you save the form to a cookie or local HTML5 storage, the data will not be automatically deleted by Digitise Forms so you may want to give the user a means to remove unwanted saves.
-
If you save the form to a database, it will be saved to a table called NDLFXSave. This table will automatically be added to your project Datasources when you use saveForm or restoreForm and will be created when you publish your form, if it doesn't already exist. You can define the location of this database in the Publishing Profile used to publish your form.
-
To reload a saved form, use the restoreForm function. This will restore the form to the state and position it was in when it was saved.
-
If you have any File Upload Elements on your form, when the form is saved any file selections will be lost, due to browser security.
When the form is restored, File Upload Elements placed directly on the form will be empty and the files will need to be reselected by the user. File Uploads performed from a Recordset's edit page, however, will still appear to have the data saved but the actual file associations will have been lost and the user will need to re-edit each row and reselect the file(s) to be uploaded.
A warning message to this effect will be displayed when you publish the form to remind you.
Using as Predefined Action in Event:
If you are assigning saveForm to an Event as a predefined action, Form Studio will automatically generate a custom JavaScript function and load the custom JavaScript file in an editor. You will need to add to the Script to create a unique ID for the save and save the ID to a cookie on the user's machine allowing it to be retrieved by the restoreForm function later. For more details of how to do this refer to the question: How do I allow users to save a partially completed form and return to it later? in the FAQs section of the User Guide.
See also: