Pass Data Between Actions and Forms

Overview

This article provides instructions for passing variable values from Actions to Forms and then retrieving the submitted form data back into Actions. It covers both server-side and client-side methods for populating form fields.

Applies To
  • Forms
  • Actions
Solution

There are two methods to pass data from an Action to a Form.

  1. Inject Custom Data with Shared Variables (Server-Side)
    You can inject server-side variables using the vars property as a second argument in your render method. This can be used to inject sensitive information without exposing it to the client-side.

    In this example, the value 123 populates the variable named: sensitive_variable
    exports.onExecutePostLogin = async (event, api) => {
      api.prompt.render(':form_id', {
        vars: {
          sensitive_variable: '123',
        }
      });
    }
    
    exports.onContinuePostLogin = async (event, api) => {
      // Add your logic after completing the form
    }

    
    
  2. Populate Values for Existing Fields (Client-Side)
    You can populate values for existing fields and hidden fields using the fields property as a second argument in your render method. Please remember to not populate any sensitive information using this method - populated values are exposed to the browser (client-side).

    In this example, the value Matt populates username field. 
    exports.onExecutePostLogin = async (event, api) => {
      api.prompt.render(':form_id', {
        fields: {
          username: 'Matt',
        }
      });
    }
    
    exports.onContinuePostLogin = async (event, api) => {
      // Add your logic after completing the form
    }

Related References

See Render Forms using Actions for examples.

Recommended content

No recommended content found...