【n8n教程】:Form Trigger 和 Form 节点,玩转表单自动化

本教程将手把手教你如何使用 n8n 的表单功能创建交互式数据收集工作流。无需编码,只需点点鼠标,就能构建专业级的自动化表单系统!

什么是 n8n Form?

n8n Form 是一组强大的节点组合,让你无需任何编程知识就能创建专业级的、可交互的网络表单。你可以用它来:

✅ 收集用户反馈和调查数据
✅ 接收客户订单或预约
✅ 自动化数据输入流程
✅ 触发复杂的业务工作流
✅ 整合表单数据到数据库或第三方应用

核心概念

两个关键节点

n8n 的表单系统由两个核心节点组成:

节点作用何时使用
Form Trigger工作流的起点,生成表单网页作为工作流的第一个节点
Form Node在工作流中间添加额外的表单页面创建多步骤表单或条件表单

重要概念


分步教程

第1步:创建你的第一个表单

A. 新建工作流

  1. 1. 打开 n8n 仪表板,点击 + 新工作流
  2. 2. 给工作流起个名字,如 "用户反馈表单"
  3. 3. 点击 创建

B. 添加 Form Trigger 节点

  1. 1. 点击画布上的 + 图标
  2. 2. 搜索 "Form Trigger",选择第一个结果
  3. 3. Form Trigger 节点会自动成为你工作流的入口

C. 配置基本信息

在 Form Trigger 节点中:

提示:使用 \n<br> 可以在描述中换行。

第2步:添加表单字段

添加文本输入字段

  1. 1. 在 Form Trigger 节点中,点击 Add Form Element
  2. 2. 选择 Text
  3. 3. 填写以下信息:
    • Field Label请输入你的名字 (用户看到的标签)
    • Element Nameuser_name (在工作流中引用的变量名)
    • Placeholder例如:张三 (提示文本)
    • Required Field:勾选 ✓(设为必填项)

添加邮箱字段

  1. 1. 再次点击 Add Form Element
  2. 2. 选择 Text (或直接使用 Text 类型,n8n 会自动验证邮箱格式)
  3. 3. 配置:
    • Field Label请输入你的邮箱
    • Element Nameuser_email
    • Placeholderyour@email.com
    • Required Field:✓

添加下拉菜单

  1. 1. Add Form ElementDropdown
  2. 2. 配置:
    • Field Label反馈类型
    • Element Namefeedback_type
    • Add Field Option:添加以下选项
      • 功能建议
      • Bug 报告
      • 其他

添加多行文本区域

  1. 1. Add Form ElementTextarea
  2. 2. 配置:
    • Field Label详细反馈内容
    • Element Namefeedback_content
    • Placeholder请详细描述你的意见...
    • Required Field:✓

第3步:测试你的表单

  1. 1. 点击 Form Trigger 节点中显示的 Test URL
  2. 2. n8n 会打开一个新标签页显示你的表单
  3. 3. 填写测试数据,点击 Submit
  4. 4. 回到编辑器,你会在节点下方看到"输出"数据

输出数据示例:


    
    
    
  {
  "user_name"
: "张三",
  "user_email"
: "[email protected]",
  "feedback_type"
: "功能建议",
  "feedback_content"
: "希望能添加深色模式"
}

第4步:配置表单完成页面

  1. 1. 在 Form Trigger 节点中,找到 Response When 选项
  2. 2. 选择 Form Is Submitted
  3. 3. 点击 Add OptionOn n8n Form Submission
  4. 4. 选择 Show Completion Screen
  5. 5. 填写:
    • Completion Title感谢反馈!
    • Completion Message我们已收到你的反馈,会尽快处理。\n感谢你的建议!

完整案例工作流 - 客户反馈收集系统

现在让我们构建一个完整的、可立即使用的工作流:当用户提交反馈表单时,自动保存数据到表格中,并发送感谢邮件。

工作流流程


    
    
    
  Form Trigger (收集数据) 
    ↓
Format Data (格式化数据)
    ↓
Google Sheets (保存数据)
    ↓
Send Email (发送感谢邮件)
    ↓
Show Completion (显示完成页面)

完整工作流 JSON 代码

将以下 JSON 复制粘贴到 n8n 中导入此工作流:


    
    
    
  {
  "name"
: "客户反馈收集与自动化系统",
  "nodes"
: [
    {

      "parameters"
: {
        "formTitle"
: "客户反馈表",
        "formDescription"
: "感谢你的反馈!请花2分钟填写此表单\n你的意见对我们改进产品非常重要",
        "formPath"
: "customer-feedback",
        "formElements"
: [
          {

            "fieldLabel"
: "你的名字",
            "fieldType"
: "text",
            "fieldName"
: "customer_name",
            "placeholder"
: "请输入你的全名",
            "requiredField"
: true
          }
,
          {

            "fieldLabel"
: "邮箱地址",
            "fieldType"
: "text",
            "fieldName"
: "customer_email",
            "placeholder"
: "[email protected]",
            "requiredField"
: true
          }
,
          {

            "fieldLabel"
: "反馈类型",
            "fieldType"
: "dropdown",
            "fieldName"
: "feedback_category",
            "fieldOptions"
: [
              {
 "name": "功能建议", "value": "feature_request" },
              {
 "name": "Bug 报告", "value": "bug_report" },
              {
 "name": "用户体验", "value": "ux_feedback" },
              {
 "name": "其他", "value": "other" }
            ]
,
            "requiredField"
: true
          }
,
          {

            "fieldLabel"
: "满意度评分 (1-5)",
            "fieldType"
: "number",
            "fieldName"
: "satisfaction_score",
            "placeholder"
: "1-5",
            "requiredField"
: true
          }
,
          {

            "fieldLabel"
: "详细反馈内容",
            "fieldType"
: "textarea",
            "fieldName"
: "feedback_message",
            "placeholder"
: "请详细描述你的意见...",
            "requiredField"
: true
          }

        ]
,
        "respondWhen"
: "formSubmitted",
        "respondWithOption"
: "showCompletionScreen",
        "completionTitle"
: "感谢你的反馈!",
        "completionMessage"
: "我们已成功收到你的反馈。\n我们的团队会在 24 小时内审阅你的意见。"
      }
,
      "type"
: "n8n-nodes-base.formTrigger",
      "typeVersion"
: 1,
      "position"
: [0, 0],
      "id"
: "node-form-trigger",
      "name"
: "Form Trigger"
    }
,
    {

      "parameters"
: {
        "mode"
: "runOnceForAllItems",
        "expression"
: "={\n  \"name\": $json.customer_name,\n  \"email\": $json.customer_email,\n  \"category\": $json.feedback_category,\n  \"score\": $json.satisfaction_score,\n  \"message\": $json.feedback_message,\n  \"timestamp\": $now.toISO()\n}",
        "options"
: {}
      }
,
      "type"
: "n8n-nodes-base.code",
      "typeVersion"
: 2,
      "position"
: [250, 0],
      "id"
: "node-format-data",
      "name"
: "Format Data"
    }
,
    {

      "parameters"
: {
        "operation"
: "insert",
        "spreadsheet"
: "YOUR_SPREADSHEET_ID",
        "sheet"
: "Feedback",
        "columns"
: "name,email,category,score,message,timestamp"
      }
,
      "type"
: "n8n-nodes-base.googleSheets",
      "typeVersion"
: 4,
      "position"
: [500, 0],
      "id"
: "node-save-sheets",
      "name"
: "Save to Google Sheets",
      "credentials"
: { "googleSheetsOAuth2": "YOUR_CREDENTIALS" }
    }
,
    {

      "parameters"
: {
        "fromEmail"
: "[email protected]",
        "to"
: "={{$json.email}}",
        "subject"
: "感谢你的反馈 - 我们已收到",
        "htmlBody"
: "<h2>亲爱的 {{$json.name}},</h2>\n<p>感谢你提交的宝贵反馈!</p>\n<p><strong>反馈类型:</strong> {{$json.category}}</p>\n<p><strong>你的评分:</strong> {{$json.score}}/5</p>\n<p>我们的团队会在 24 小时内审阅你的意见,如有问题会主动联系你。</p>\n<p>谢谢!</p>",
        "options"
: {}
      }
,
      "type"
: "n8n-nodes-base.sendGrid",
      "typeVersion"
: 1,
      "position"
: [750, 0],
      "id"
: "node-send-email",
      "name"
: "Send Thank You Email",
      "credentials"
: { "sendGridApi": "YOUR_CREDENTIALS" }
    }

  ]
,
  "connections"
: {
    "Form Trigger"
: {
      "main"
: [[{ "node": "Format Data", "branch": 0, "socket": 0 }]]
    }
,
    "Format Data"
: {
      "main"
: [[{ "node": "Save to Google Sheets", "branch": 0, "socket": 0 }]]
    }
,
    "Save to Google Sheets"
: {
      "main"
: [[{ "node": "Send Thank You Email", "branch": 0, "socket": 0 }]]
    }

  }
,
  "active"
: false,
  "settings"
: {}
}

如何使用此工作流

  1. 1. 导入工作流
    • • 复制上面的 JSON 代码
    • • 在 n8n 中新建工作流
    • • 点击 菜单Import from File 或直接粘贴
    • • 选择 Ctrl+V 粘贴到画布
  2. 2. 配置凭据
    • • 点击 "Save to Google Sheets" 节点,配置 Google Sheets 凭据
    • • 点击 "Send Thank You Email" 节点,配置 SendGrid 或其他邮件服务凭据
  3. 3. 自定义字段
    • • 修改表单字段以满足你的需求
    • • 调整完成页面的文案
  4. 4. 激活工作流
    • • 点击右上角 Activate 按钮
    • • 使用 Production URL 分享你的表单

高级用法

使用查询参数预填表单

你可以通过 URL 参数预填表单字段(仅限生产环境)。

示例


    
    
    
  https://my-account.n8n.cloud/form/customer-feedback?customer_name=John&customer_email=john%40example.com

注意:特殊字符需要进行 URL 编码(例如 @ 变为 %40,空格变为 %20

创建多步骤表单

使用 Form Node(非 Trigger)创建表单的后续页面:

  1. 1. 在 Form Trigger 后添加处理逻辑
  2. 2. 插入 Form Node,配置第二页面
  3. 3. Form Node 会在同一表单中显示新页面
  4. 4. 用户可以在页面之间导航

隐藏字段

添加不显示给用户但会包含在表单数据中的字段:

  1. 1. Add Form ElementHidden Field
  2. 2. 设置 Field NameField Value
  3. 3. 你也可以通过查询参数动态传递隐藏字段的值

显示自定义 HTML

在表单中嵌入富文本内容:

  1. 1. Add Form ElementCustom HTML
  2. 2. 在 HTML 框中添加你的内容
  3. 3. 支持的元素:链接、图片、视频等
  4. 4. 不支持<script><style><input> 标签

常见问题解答

Q:我看不到表单提交的数据?

A:检查以下几点:

Q:如何限制文件上传的类型?

A:在 File 字段中使用 acceptFileTypes 参数。例如:

Q:表单可以重定向到其他网站吗?

A:可以!在完成选项中选择 Redirect to URL,输入目标地址。

Q:多个用户同时提交表单会怎样?

A:n8n 会为每个提交创建独立的执行流程,自动并发处理,互不干扰。

Q:可以跳过某些问题吗?

A:可以!不勾选 Required Field 即可让字段为可选。或使用 Switch 节点根据前序数据条件显示不同问题。

Q:如何保护表单不被滥用?

A


快速参考:所有表单字段类型

字段类型用途示例
Text单行文本输入名字、城市、电话
Textarea多行文本评论、反馈、描述
Number数值输入评分、数量、年龄
Password密码输入登录密码、PIN
Email邮箱输入用户邮箱
Date日期选择器生日、预约日期
Dropdown下拉菜单类别、国家、选项
Checkbox复选框同意条款、多选项
Radio单选按钮选一个选项
File文件上传文档、图片、附件
Custom HTML自定义内容说明、链接、媒体
Hidden Field隐藏字段追踪数据、用户ID

引用链接

[1] 官方文档: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.form/
[2] n8n系列教程: https://www.undsky.com/blog/?category=n8n%E6%95%99%E7%A8%8B#