n8n 表单触发器节点#
¥n8n Form Trigger node
使用 n8n 表单触发器在用户提交表单时启动工作流,并从表单中获取输入数据。该节点会生成供你使用的表单网页。
¥Use the n8n Form trigger to start a workflow when a user submits a form, taking the input data from the form. The node generates the form web page for you to use.
你可以添加更多页面,以便使用 n8n 表单 节点继续表单。
¥You can add more pages to continue the form with the n8n Form node.
构建和测试工作流#
¥Build and test workflows
构建或测试工作流时,请使用测试 URL。使用测试 URL 可确保你可以在编辑器 UI 中查看传入数据,这对于调试非常有用。
¥While building or testing a workflow, use the Test URL. Using a test URL ensures that you can view the incoming data in the editor UI, which is useful for debugging.
测试有两种方法:
¥There are two ways to test:
- 选择“执行步骤”。n8n 打开表单。当你提交表单时,n8n 会运行该节点,但不会运行工作流的其余部分。
¥Select Execute Step. n8n opens the form. When you submit the form, n8n runs the node, but not the rest of the workflow.
- 选择“执行工作流”。n8n 打开表单。当你提交表单时,n8n 会运行整个工作流。
¥Select Execute Workflow. n8n opens the form. When you submit the form, n8n runs the workflow.
生产工作流#
¥Production workflows
当你的工作流准备就绪后,切换到使用生产环境 URL。然后你可以激活你的工作流,n8n 会在用户提交表单时自动运行它。
¥When your workflow is ready, switch to using the Production URL. You can then activate your workflow, and n8n runs it automatically when a user submits the form.
使用生产 URL 时,请确保已保存并激活工作流。使用生产 URL 时,通过表单触发器流出的数据在编辑器 UI 中不可见。
¥When working with a production URL, ensure that you have saved and activated the workflow. Data flowing through the Form trigger isn't visible in the editor UI with the production URL.
使用查询参数设置默认选择#
¥Set default selections with query parameters
你可以使用 查询参数 和 n8n 表单触发器提供的初始 URL 来设置字段的初始值。每个 表单中的页面 都会接收发送到 n8n 表单触发器 URL 的相同查询参数。
¥You can set the initial values for fields by using query parameters with the initial URL provided by the n8n Form Trigger. Every page in the form receives the same query parameters sent to the n8n Form Trigger URL.
Only for production
查询参数仅在生产模式下使用表单时可用。在测试模式下,n8n 不会根据查询参数填充字段值。
¥Query parameters are only available when using the form in production mode. n8n won't populate field values from query parameters in testing mode.
使用查询参数时,请将任何包含特殊字符的字段名称或值标记为 percent-encode。此功能确保 n8n 使用给定字段的初始值。你可以使用 URL 编码/解码 等工具,通过百分比编码格式化查询参数。
¥When using query parameters, percent-encode any field names or values that use special characters. This ensures n8n uses the initial values for the given fields. You can use tools like URL Encode/Decode to format your query parameters using percent-encoding.
例如,假设你有一个包含以下属性的表单:
¥As an example, imagine you have a form with the following properties:
- 生产环境 URL:
https://my-account.n8n.cloud/form/my-form
¥Production URL: https://my-account.n8n.cloud/form/my-form
- 字段:
¥Fields:
-
name:Jane Doe -
email:jane.doe@example.com
使用查询参数和百分比编码,你可以使用以下 URL 将上述数据的初始字段值设置为:
¥With query parameters and percent-encoding, you could use the following URL to set initial field values to the data above:
1 | |
在这里,百分比编码会将 at 符号 (@) 替换为字符串 %40,并将空格字符 () 替换为字符串 %20。无论这些字段出现在表单的哪个页面上,此操作都会设置它们的初始值。
¥Here, percent-encoding replaces the at-symbol (@) with the string %40 and the space character () with the string %20. This will set the initial value for these fields no matter which page of the form they appear on.
节点参数#
¥Node parameters
以下是主要的节点配置字段:
¥These are the main node configuration fields:
验证#
¥Authentication
- 基本身份验证
¥Basic Auth
- 无
¥None
使用基本身份验证#
¥Using basic auth
要配置此凭据,你需要:
¥To configure this credential, you'll need:
- 用于访问 HTTP 请求目标应用或服务的用户名。
¥The Username you use to access the app or service your HTTP Request is targeting.
- 与该用户名关联的密码。
¥The Password that goes with that username.
表单 URL#
¥Form URLs
“表单触发器”节点有两个 URL:测试 URL 和生产 URL。n8n 在节点面板顶部显示 URL。选择“测试 URL”或“生产 URL”以切换 n8n 显示的 URL。
¥The Form Trigger node has two URLs: Test URL and Production URL. n8n displays the URLs at the top of the node panel. Select Test URL or Production URL to toggle which URL n8n displays.
- 测试 URL:当你选择“执行步骤”或“执行工作流”(如果工作流未激活)时,n8n 会注册一个测试 Webhook。当你调用 URL 时,n8n 会在工作流中显示数据。
¥Test URL: n8n registers a test webhook when you select Execute Step or Execute Workflow, if the workflow isn't active. When you call the URL, n8n displays the data in the workflow.
- 生产环境 URL:激活工作流时,n8n 会注册一个生产环境 Webhook。使用生产环境 URL 时,n8n 不会在工作流中显示数据。你仍然可以查看生产环境执行的工作流数据。在工作流中选择“执行”选项卡,然后选择要查看的工作流执行。
¥Production URL: n8n registers a production webhook when you activate the workflow. When using the production URL, n8n doesn't display the data in the workflow. You can still view workflow data for a production execution. Select the Executions tab in the workflow, then select the workflow execution you want to view.
表单路径#
¥Form Path
为表单设置自定义别名。
¥Set a custom slug for the form.
表单标题#
¥Form Title
输入表单标题。n8n 将表单标题显示为网页标题和表单主标题 h1。
¥Enter the title for your form. n8n displays the Form Title as the webpage title and main h1 title on the form.
表单描述#
¥Form Description
输入表单的描述。n8n 将表单描述显示为表单主标题 h1 下方的副标题。使用 \n 或 <br> 添加换行符。
¥Enter the description for your form. n8n displays the Form Description as a subtitle below the main h1 title on the form. Use \n or <br> to add a line break.
表单元素#
¥Form Elements
创建表单的问题字段。选择“添加表单元素”以添加新字段。
¥Create the question fields for your form. Select Add Form Element to add a new field.
每个字段都有以下设置:
¥Every field has the following settings:
- 字段标签:输入渲染表单中输入字段上方显示的标签。
¥Field Label: Enter the label that appears above the input field on the rendered form.
- 字段名称:此名称用于表单触发器节点的输出。使用它将在下游节点中引用表单字段。
¥Field Name: This name is used in the output of the Form Trigger node. Use it to reference a form field in downstream nodes.
- 元素类型:选择复选框、自定义 HTML、日期、下拉列表、电子邮件、文件、隐藏字段、数字、密码、单选按钮、文本或文本区域。
¥Element Type: Choose from Checkboxes, Custom HTML, Date, Dropdown, Email, File, Hidden Field, Number, Password, Radio Buttons, Text, or Textarea.
-
选择“复选框”在表单中包含复选框元素。默认情况下,表单用户可以选择的复选框数量没有限制。你可以通过为“限制选择”选项指定值(例如“精确数字”、“范围”或“无限制”)来设置限制。
¥Select Checkboxes to include checkbox elements in the form. By default, there is no limit on how many checkboxes a form user can select. You can set the limit by specifying a value for the Limit Selection option as Exact Number, Range, or Unlimited.
-
选择“自定义 HTML”以插入任意 HTML 代码。
¥Select Custom HTML to insert arbitrary HTML.
- 你可以包含链接、图片、视频等元素。无法包含
<script>、<style>或<input>元素。
¥You can include elements like links, images, video, and more. You can't include
<script>,<style>, or<input>elements.- 默认情况下,自定义 HTML 字段不会包含在节点输出中。要在输出中包含自定义 HTML 内容,请填写关联的元素名称字段。
¥By default, Custom HTML fields aren't included in the node output. To include the Custom HTML content in the output, fill out the associated Element Name field.
- 你可以包含链接、图片、视频等元素。无法包含
-
选择“日期”以在表单中包含日期选择器。有关日期格式的更多信息,请参阅 使用 Luxon 处理日期和时间。
¥Select Date to include a date picker in the form. Refer to Date and time with Luxon for more information on formatting dates.
-
选择“下拉列表”>“添加字段选项”以添加多个选项。默认情况下,下拉菜单为单选。要将其设置为多选题,请启用“多选题”选项。
¥Select Dropdown List > Add Field Option to add multiple options. By default, the dropdown is single-choice. To make it multiple-choice, turn on Multiple Choice.
-
选择“单选按钮”以在表单中包含单选按钮元素。
¥Select Radio Buttons to include radio button elements in the form.
-
选择“隐藏字段”以包含表单元素,但不将其显示在表单上。你可以使用“字段值”参数设置默认值,或使用 查询参数 传递字段值。
¥Select Hidden Field to include a form element without displaying it on the form. You can set a default value using the Field Value parameter or pass values for the field using query parameters.
-
占位符:定义要在兼容的表单元素中显示的示例文本。电子邮件、调用号码、密码、文本和文本区域均支持占位符。
¥Placeholder: Define a sample text to display inside compatible form elements. Placeholders are supported in Email, Number, Password, Text and Textarea.
- 默认值:定义一个默认值,该值将在兼容的表单元素中预先填充或预先选中。除自定义 HTML、文件、隐藏字段和密码外,所有表单元素均支持默认值。
¥Default value: Define a default value that will be pre-filled or pre-selected in compatible form elements. Default values are supported in all form elements except Custom HTML, File, Hidden Field, and Password.
- 必填字段:启用此功能可要求用户填写表单中的此字段。
¥Required Field: Turn on to require users to complete this field on the form.
响应条件#
¥Respond When
选择 n8n 何时对表单提交发送响应。你可以响应以下情况:
¥Choose when n8n sends a response to the form submission. You can respond when:
- 表单已提交:用户提交表单后立即向其发送响应
¥Form Is Submitted: Send a response to the user as soon as they submit the form.
- 工作流已完成:如果你希望在向用户发送响应之前完成工作流的执行,请使用此选项。如果工作流出错,它会向用户发送响应,告知其表单提交出现问题。
¥Workflow Finishes: Use this if you want the workflow to complete its execution before you send a response to the user. If the workflow errors, it sends a response to the user telling them there was a problem submitting the form.
节点选项#
¥Node options
选择“添加选项”以查看更多配置选项:
¥Select Add Option to view more configuration options:
- 附加 n8n 归属:关闭此选项以隐藏表单底部带有 n8n 属性的表单自动化信息。
¥Append n8n Attribution: Turn off to hide the Form automated with n8n attribute at the bottom of the form.
- 按钮标签:表单提交按钮的标签。n8n 将按钮标签显示为提交按钮的名称。
¥Button Label: The label to use for your form's submit button. n8n displays the Button Label as the name of the submit button.
- 表单路径:表单 URL 的最后一部分,适用于测试和生产环境。替换自动生成的 UUID 作为最终组件。
¥Form Path: The final segment of the form's URL, for both testing and production. Replaces the automatically generated UUID as the final component.
- 忽略机器人:启用此功能可忽略来自链接预览器和网络爬虫等机器人的请求。
¥Ignore Bots: Turn on to ignore requests from bots like link previewers and web crawlers.
- 使用工作流时区:启用此选项以使用 工作流设置 中的时区而非 UTC(默认)。这会影响节点输出中
submittedAt时间戳的值。
¥Use Workflow Timezone: Turn on to use the timezone in the Workflow settings instead of UTC (default). This affects the value of the submittedAt timestamp in the node output.
- 自定义表单样式:使用 CSS 覆盖公共表单界面的默认样式。该字段会预先填充默认样式,因此你可以仅更改所需的内容。
¥Custom Form Styling: Override the default styling of the public form interface with CSS. The field pre-populates with the default styling so you can change only what you need to.
自定义表单触发器节点行为#
¥Customizing Form Trigger node behavior
使用换行符格式化响应文本#
¥Format response text with line breaks
你可以使用以下方法之一向表单响应文本添加换行符:
¥You can use one of the following methods to add line breaks to form response text:
• 在 formSubmittedText 字段中使用 HTML 格式而非纯文本 • 在发送响应之前,将换行符 (\n) 替换为 HTML 换行符 (<br>) • 如果需要更精细的格式控制,请考虑使用自定义 HTML 响应页面
¥• Use HTML formatting instead of plain text in the formSubmittedText field
• Replace newline characters (\n) with HTML break tags (<br>) before sending the response
• Consider using a custom HTML response page if you need more formatting control
通过身份验证限制表单访问#
¥Restrict form access with authentication
你可以使用以下选项之一向表单添加身份验证:
¥You can use one of the following options to add authentication to your form:
• 使用 OTP(一次性密码)字段和 TOTP 节点验证进行基于令牌的身份验证 • 添加一个带有表单身份验证的 Wait 节点作为辅助表单页面 • 将哈希密码存储在数据库中,并与表单提交内容进行比较以进行验证 • 如果需要高级身份验证,请使用外部身份验证提供商,例如 Google 表单
¥• Use the OTP (One-Time Password) field with TOTP node validation for token-based authentication • Add a Wait node with form authentication as a secondary form page • Store hashed passwords in a database and compare against form submissions for validation • Use external authentication providers like Google Forms if you need advanced authentication
模板和示例#
¥Templates and examples
