Wiki source code of Export als Persistence-Datei


Show last authors
1 {{figure image="export_persistence_en.png" width="400" clear="h1"}}
2 User interface for actions of type //Export to persistence file//.
3 {{/figure}}
4
5 Action of type //Export to persistence file// allows to provide the data of an form record as a persisted structure. This can be reloaded later to restore the form. This action and javascript code for loading the persisted values can thus be used to implement saving form data.
6
7 == Parameters ==
8
9 === Storage options for the created files ===
10
11 ; Output file name
12 : Name of the output file.
13 ; Attach file to form record
14 : If this option is selected, files created in this action will be attached to the form record. Otherwise, they are only available for other actions within the workflow processing in the same processing chain.
15
16 == Action variables ==
17
18 Actions of type //Export to persistence file// provide [[Action variables>>Formcycle.UserInterface.Variables||anchor="HActionvariables"]] which can be used in subsequent actions.
19
20 === Standard action variables ===
21
22 ; [%$<action name>.SUCCESS%]
23 : Return whether action was successfully executed. Returns Boolean (true/false).
24 ; [%$<action name>.RESULT%]
25 : Return all results provided by the action in structured form.
26
27 ; [%$<action name>.ERROR_CODE%]
28 : The error code thrown in case of an error in the action. Empty if no error occurred.
29 ; [%$<action name>.ERROR_MESSAGE%]
30 : The thrown error message in the action's error case. Empty if no error occurred.
31
32 === Action specific action variables ===
33
34 ; [%$<action name>.RESULT.fileSize%]
35 : Size of the created persistence file, in bytes.
36 ; [%$<action name>.ERROR.message%]
37 : Error code returned if the persistence file could not be written to the file system.
38
39 == Import form data from export file ==
40
41 If a form is called and there is a non-empty upload field named {{code language="none"}}fcp_persistence{{/code}} in the form or there is a file named {{code language="none"}}fcp-persistence{{/code}} in another upload field, the values from the persistence file will be written to form when the form is delivered, thus pre-populating fields.
42
43 The following example code allows to realize this process with a button. Here, the form's target is set to its own URL on submit and all input fields except the upload field are disabled. Then a submit of the form is executed, through which the contents of the file are loaded.
44
45 {{code language="javascript"}}
46 $('BUTTON[name="btnLoad"]').on('click', function(){
47 $('.xm-form').attr('action', window.location);
48 $('.xm-form input').not('[name=fcp_persistence]').attr('disabled', "disabled");
49 $('.xm-form textarea').attr('disabled', "disabled");
50 $('.xm-form select').attr('disabled', "disabled");
51 xm_validator.disable();
52 $('.xm-form').trigger("submit");
53 });
54 $('[xn="fcp_persistence"] .img-uploaded-preview').visible(false);
55 {{/code}}
56
57 Alternatively, the following code can be used:
58
59 {{code language="javascript"}}
60 $('document').ready(function(){
61 var nameOfTriggerButton="btnLoad";
62
63 var form = $("<form>", {
64 action:"?",
65 method: "post",
66 enctype: "multipart/form-data"
67 }).appendTo('body');
68
69 var upload = $("<input>", {
70 type: "file",
71 name: "fcp_persistence"
72 }).appendTo(form);
73
74 upload.change(function(){form.submit()});
75 $('BUTTON[name="'+nameOfTriggerButton+'"]').click(function(){upload.trigger('click')});
76 })
77 {{/code}}