Function Repository Resource:

PersistentCloudForm

Source Notebook

Create forms with persistent values for cloud deployment

Contributed by: Jon McLoone

ResourceFunction["PersistentCloudForm"][form,store]

modifies form so that it has persistent user-specific values, storing values in CloudExpression[store].

Details and Options

The form must be either a FormPage or FormFunction.
The store must be either a String or a CloudExpression containing an Association with PartProtectionNone.
The output is an APIFunction expression, which typically is deployed with CloudDeploy or CloudPublish for use in the cloud.
The output should not be deployed with Permissions"Public" for long-term persistence or if sensitive information is being stored. Unauthenticated users will be tracked using a combination of IP address and browser details, giving a risk that another user could share the same values, and also resulting in loss of data if these details change.

Examples

Basic Examples (4) 

Deploy a simple GDPR (General Data Protection Regulation) permissions form:

In[1]:=
CloudDeploy[
 ResourceFunction["PersistentCloudForm"][
  FormFunction[{
    "Name" -> "String",
    {"GDPRPermission", "I agree"} -> {"no", "yes"}},
   AppearanceRules -> <|
     "Title" -> "Mailing preferences", "Description" -> "Please confirm that you give permission for us to send you email"|>, If[#GDPRPermission === "yes", "Thank you, we will keep in touch.", "OK, we won't mail you."] &], "myApp"], Permissions -> "Authenticated" -> "Execute"]
Out[1]=

When a user returns to the form, its state will reflect the last values that they submitted. These values can then be changed:

A CloudExpression is created to store the data:

In[2]:=
CloudExpression["myApp"][All]
Out[2]=

You can look up whether user "mcloone@wolfram.com" is currently giving their permission to be sent email:

In[3]:=
CloudExpression["myApp"]["mcloone@wolfram.com", "GDPRPermission"]
Out[3]=

Scope (1) 

Both FormPage and FormFunction are supported. Create a simple persistent GDPR permissions form that redirects the user on completion:

In[4]:=
CloudDeploy[
 ResourceFunction["PersistentCloudForm"][
  FormFunction[{
    "Name" -> "String",
    {"GDPRPermission", "I agree"} -> {"no", "yes"}},
   AppearanceRules -> <|
     "Title" -> "Mailing preferences", "Description" -> "PPPlease confirm that you give permission for us to send you email"|>, HTTPRedirect["http://wolfram.com"] &], "myApp"], Permissions -> "Authenticated" -> "Execute"]
Out[4]=

Properties and Relations (1) 

The data is stored in a CloudExpression. Changes to the values in the CloudExpression will be seen by the user when they visit form. For example, you can pre-populate the form for a user who has not used it yet:

In[5]:=
AssociateTo[CloudExpression["myApp"], "user@test.com" -> <|"Name" -> "John Doe", "GDPRPermission" -> "no"|>];

Publisher

Jon McLoone

Version History

  • 1.0.0 – 06 August 2020

Related Resources

License Information