Form icon

Form

Captures user input through a form

Overview

This node, named "Form", is designed to capture user input through a customizable form within an n8n workflow. It allows defining various aspects of the form such as its display text, validation rules, branching logic, and processing code. The node supports running custom JavaScript or Python code either once for all input items or individually per item, enabling flexible data manipulation and validation.

Common scenarios where this node is beneficial include:

  • Interactive workflows that require user feedback or data entry.
  • Conditional branching based on user responses.
  • Data validation and transformation before passing data downstream.
  • Implementing dynamic forms with custom processing logic embedded.

For example, you could use this node to create a survey form in a workflow, validate the inputs against specific patterns, and branch the workflow depending on answers provided by users.

Properties

Name Meaning
Path Defines whether this form node represents the main path of the workflow or a branch. Options: "Main", "Branch".
Node Name A short descriptive name for the form node.
Node Type The type of the node, typically indicating the form's purpose (default is "MENU").
Validation Failure Text Text displayed if the user enters an invalid value according to the validation rule.
Node Display Text The message or prompt shown when this form node is active.
Input VariableName The name of the variable expected as input from the user.
Input Validation A regular expression string used to validate the user's input.
Node Status Indicates whether the node is active, inactive, or in test mode. Options: "Active", "Inactive", "Test".
Variables A collection of variables with their names, types (String, Number, JSONArray, JSONObject), and values that can be used within the form or processing logic.
Choose Processor Allows specifying processors to execute at different stages: Pre Processor, Input Processor, Post Processor. Each processor is identified by a name or value string.
Mode Determines how the processing code runs: either once for all input items ("Run Once for All Items") or once per each input item ("Run Once for Each Item").
Language Programming language for the processor code. Options include "JavaScript" and "Python (Beta)".
JavaScript The actual JavaScript code to execute as part of the processing logic. This property is shown conditionally based on version, language, and mode.
Skip Rule A rule defined as a string that determines if this node should be skipped during execution.
Branching Rule Rules that define branching logic, allowing the workflow to take different paths based on conditions. Includes node branch and text branch options.
Flags Collection of boolean flags controlling behavior such as sanitizing input, encrypting user input, marking the node as last in the workflow, closing the session, or publishing the output.

Output

The node outputs JSON data representing the processed form data. The structure includes:

  • The main json field containing the standardized output of the executed processor code or the raw input data if no processing occurs.
  • If errors occur during processing, the output JSON will contain an error field with the error message.
  • When running in "Run Once for Each Item" mode, outputs are paired with their corresponding input item index.
  • Binary data can also be included in the output if produced by the processor code, though this is optional and depends on the custom code.

Dependencies

  • The node relies on an internal sandbox environment to safely execute user-provided JavaScript or Python code.
  • It uses lodash's set function for object manipulation.
  • Environment variable CODE_ENABLE_STDOUT controls whether console logs from the sandboxed code are output to the browser console.
  • No external API keys or services are required by default; however, user code may depend on external resources if implemented accordingly.

Troubleshooting

  • Code Execution Errors: If the custom processor code throws exceptions, the node captures these and outputs an error message in the JSON. To resolve, review and debug the custom code.
  • Validation Failures: If user input does not match the specified regular expression, the node displays the configured validation failure text.
  • Skipping Nodes: If the skip rule evaluates to true, the node will be bypassed; ensure the skip rule syntax is correct.
  • Branching Logic Issues: Incorrect branching rules may cause unexpected workflow paths; verify the branching expressions carefully.
  • Console Logs Not Visible: If debugging output is missing, check that the environment variable enabling stdout logging is set appropriately.

Links and References

Discussion