Wiki source code of Export (Persistence)
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{figure image="export_persistence_en.png" clear="h1"}} | ||
2 | User interface for editing actions of type //Export (Persistence)//. | ||
3 | {{/figure}} | ||
4 | |||
5 | Actions of type //export (persistence)// allow you to export the data of a form record, i.e. the data that has been submitted with the form. With a little bit of Javascript code, the exported data can be imported again later. This way it becomes possible to save form record data locally and restore it from a local backup. Filling form fields with data stored in an XML file is also possible via the actions of type [[//Import form values from XML//>>Formcycle.UserInterface.MyForms.WorkflowProcessing.Actions.ImportXML]]. | ||
6 | |||
7 | == Options == | ||
8 | |||
9 | ; Output file name | ||
10 | : The name for the export file. | ||
11 | |||
12 | ; Attach file to form record | ||
13 | : Determines whether the generated output file should be attached to the operation. | ||
14 | |||
15 | == Importing form data from a persistence file == | ||
16 | |||
17 | When you open a form and the form contains a non-empty upload field named {{code language="none"}}fcp_persistence{{/code}}, or some other upload field contains a file whose file name without the extension is {{code language="none"}}fcp-persistence{{/code}}, form fields are pre-filled with the data form the persistence file. | ||
18 | |||
19 | The following example code makes it possible to realize this process with a button. The target of the form is set to its own URL when it is sent and all input fields except the upload field are deactivated. Subsequently, a submit of the form is executed which loads the contents of the file. | ||
20 | |||
21 | {{code language="javascript"}} | ||
22 | $('BUTTON[name="btnLoad"]').on('click', function(){ | ||
23 | $('.xm-form').attr('action', window.location); | ||
24 | $('.xm-form input').not('[name=fcp_persistence]').attr('disabled', "disabled"); | ||
25 | $('.xm-form textarea').attr('disabled', "disabled"); | ||
26 | $('.xm-form select').attr('disabled', "disabled"); | ||
27 | $('.xm-form').submit(); | ||
28 | }); | ||
29 | $('[xn="fcp_persistence"] .img-uploaded-preview').visible(false); | ||
30 | {{/code}} | ||
31 | |||
32 | Alternatively the following code can be used: | ||
33 | |||
34 | {{code language="javascript"}} | ||
35 | $('document').ready(function(){ | ||
36 | var nameOfTriggerButton= "btnLoad"; | ||
37 | |||
38 | var form = $("<form>", { | ||
39 | action:"?", | ||
40 | method:"post", | ||
41 | enctype:"multipart/form-data" | ||
42 | }).appendTo('body'); | ||
43 | |||
44 | var upload = $("<input>", { | ||
45 | type:"file", | ||
46 | name:"fcp_persistence" | ||
47 | }).appendTo(form); | ||
48 | |||
49 | upload.change(function(){form.submit()}); | ||
50 | $('BUTTON[name="'+nameOfTriggerButton+'"]').click(function(){upload.trigger('click')}); | ||
51 | }) | ||
52 | {{/code}} | ||
53 | |||
54 | {{info}} | ||
55 | [[You may also download an example form>>attach:Local import and export.zip]] illustrating this process and how to setup the workflow. | ||
56 | {{/info}} |