本教程将手把手教你如何使用 n8n 的表单功能创建交互式数据收集工作流。无需编码,只需点点鼠标,就能构建专业级的自动化表单系统!
n8n Form 是一组强大的节点组合,让你无需任何编程知识就能创建专业级的、可交互的网络表单。你可以用它来:
✅ 收集用户反馈和调查数据
✅ 接收客户订单或预约
✅ 自动化数据输入流程
✅ 触发复杂的业务工作流
✅ 整合表单数据到数据库或第三方应用
n8n 的表单系统由两个核心节点组成:
| 节点 | 作用 | 何时使用 |
|---|---|---|
| Form Trigger | 工作流的起点,生成表单网页 | 作为工作流的第一个节点 |
| Form Node | 在工作流中间添加额外的表单页面 | 创建多步骤表单或条件表单 |
在 Form Trigger 节点中:
https://your-domain.n8n.cloud/form/user-feedback提示:使用 \n 或 <br> 可以在描述中换行。
请输入你的名字 (用户看到的标签)user_name (在工作流中引用的变量名)例如:张三 (提示文本)请输入你的邮箱user_emailyour@email.com反馈类型feedback_type功能建议Bug 报告其他详细反馈内容feedback_content请详细描述你的意见...输出数据示例:
{
"user_name": "张三",
"user_email": "[email protected]",
"feedback_type": "功能建议",
"feedback_content": "希望能添加深色模式"
}感谢反馈!我们已收到你的反馈,会尽快处理。\n感谢你的建议!现在让我们构建一个完整的、可立即使用的工作流:当用户提交反馈表单时,自动保存数据到表格中,并发送感谢邮件。
Form Trigger (收集数据)
↓
Format Data (格式化数据)
↓
Google Sheets (保存数据)
↓
Send Email (发送感谢邮件)
↓
Show Completion (显示完成页面)将以下 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": {}
}你可以通过 URL 参数预填表单字段(仅限生产环境)。
示例:
https://my-account.n8n.cloud/form/customer-feedback?customer_name=John&customer_email=john%40example.com注意:特殊字符需要进行 URL 编码(例如 @ 变为 %40,空格变为 %20)
使用 Form Node(非 Trigger)创建表单的后续页面:
添加不显示给用户但会包含在表单数据中的字段:
在表单中嵌入富文本内容:
<script>、<style>、<input> 标签A:检查以下几点:
A:在 File 字段中使用 acceptFileTypes 参数。例如:
.pdf,.doc,.docx - 只允许文档.jpg,.png,.gif - 只允许图片A:可以!在完成选项中选择 Redirect to URL,输入目标地址。
A:n8n 会为每个提交创建独立的执行流程,自动并发处理,互不干扰。
A:可以!不勾选 Required Field 即可让字段为可选。或使用 Switch 节点根据前序数据条件显示不同问题。
A:
| 字段类型 | 用途 | 示例 |
|---|---|---|
| Text | 单行文本输入 | 名字、城市、电话 |
| Textarea | 多行文本 | 评论、反馈、描述 |
| Number | 数值输入 | 评分、数量、年龄 |
| Password | 密码输入 | 登录密码、PIN |
| 邮箱输入 | 用户邮箱 | |
| 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#