8
n8n 中文网amn8n.com

带数据验证和MongoDB集成的联系表单工作流

高级

这是一个Lead Generation, Multimodal AI领域的自动化工作流,包含 16 个节点。主要使用 Set, Code, Form, MongoDb, FormTrigger 等节点。 处理联系表单提交,包含验证和MongoDB存储

前置要求
  • MongoDB 连接字符串
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "9loQL9vFR9lofvwj",
  "meta": {
    "instanceId": "2726cca490aa82c0ebb012bdcdb3596cbc823e0d9b0e26be2ae4efed4df5b51c",
    "templateCredsSetupCompleted": true
  },
  "name": "带数据验证和 MongoDB 集成的联系表单工作流",
  "tags": [],
  "nodes": [
    {
      "id": "63569954-4739-4730-81eb-a004f3f24fd8",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        -384
      ],
      "parameters": {
        "width": 1536,
        "height": 624,
        "content": "# n8n 工作流:带数据验证和 MongoDB 集成的联系表单工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "5af1ce8f-100b-48e4-bb0a-81e7bbb78861",
      "name": "验证模式",
      "type": "n8n-nodes-base.code",
      "position": [
        208,
        80
      ],
      "parameters": {
        "jsCode": "const item = $input.first();\n\n// Validate Phone Number\nconst phone = item.json[\"Phone Number\"];\nconst phoneRegex = /^(\\+?\\d{1,4}[\\s-]?)?(\\(?\\d{1,4}\\)?[\\s-]?)?[\\d\\s-]{5,}$/;\nif (!phoneRegex.test(phone)) {\n  item.json[\"Phone Number\"] = \"Is not Valid\";\n}\n\n// Validate other fields for dangerous patterns\nconst dangerousPattern = /('|;|--|\\/\\*|\\*\\/|xp_|exec|drop|select|insert|delete|update|union|script|<|>)/i;\nfor (const field of [\"Name\", \"Last Name\", \"Email\"]) {\n  const value = item.json[field];\n  if (dangerousPattern.test(value)) {\n    item.json[field] = \"Is not Valid\";\n  }\n}\n\nreturn item.json;"
      },
      "typeVersion": 2
    },
    {
      "id": "afac30d0-547d-412b-b42d-16948ac42ae0",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        -48
      ],
      "parameters": {
        "color": 5,
        "width": 688,
        "height": 192,
        "content": "### 1. 表单提交时"
      },
      "typeVersion": 1
    },
    {
      "id": "1142f3b4-caf6-43fa-a200-ecb9da3acf86",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        176
      ],
      "parameters": {
        "color": 5,
        "width": 688,
        "height": 208,
        "content": "### 2. 代码节点(验证层)"
      },
      "typeVersion": 1
    },
    {
      "id": "158c7af4-ecb2-4af6-b487-9e73513c5eab",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        432
      ],
      "parameters": {
        "color": 5,
        "width": 688,
        "height": 176,
        "content": "### 3. 编辑字段节点(数据格式化)"
      },
      "typeVersion": 1
    },
    {
      "id": "8412f473-fb8d-42e0-bd13-d317196ad36d",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 198,
        "height": 240,
        "content": "## 1"
      },
      "typeVersion": 1
    },
    {
      "id": "112fa7b6-f7f5-4a2c-afe9-bc7778d50e97",
      "name": "便签9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 198,
        "height": 240,
        "content": "## 2"
      },
      "typeVersion": 1
    },
    {
      "id": "f52b7c18-5126-4d1d-962a-c696097c7fe6",
      "name": "便签10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        608,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 198,
        "height": 240,
        "content": "## 4"
      },
      "typeVersion": 1
    },
    {
      "id": "7a5783da-8617-4b60-b29c-b427c1c16289",
      "name": "表单提交时",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -16,
        80
      ],
      "webhookId": "a87e98a4-aa64-4939-b6da-10213d7f7d57",
      "parameters": {
        "options": {
          "ignoreBots": true,
          "appendAttribution": false
        },
        "formTitle": "📩 Get in Touch with Us",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Name",
              "placeholder": "Name",
              "requiredField": true
            },
            {
              "fieldLabel": "Last Name",
              "placeholder": "Last Name",
              "requiredField": true
            },
            {
              "fieldType": "email",
              "fieldLabel": "Email",
              "placeholder": "Email",
              "requiredField": true
            },
            {
              "fieldLabel": "Phone Number",
              "placeholder": "(+XX ) XXXXXXXX",
              "requiredField": true
            }
          ]
        },
        "formDescription": "We’d love to hear from you! Whether you have a question, feedback, or simply want to connect, fill out the form below and our team will get back to you as soon as possible"
      },
      "typeVersion": 2.3
    },
    {
      "id": "299f1e43-a848-4c9d-8c4c-1759a5ca7aca",
      "name": "插入文档",
      "type": "n8n-nodes-base.mongoDb",
      "position": [
        656,
        80
      ],
      "parameters": {
        "fields": "name, last_name, email, phone, submitted_at",
        "options": {
          "dateFields": "={{ $json.name }},{{ $json.last_name }},{{ $json.email }},{{ $json.phone }},{{ $json.submitted_at }}",
          "useDotNotation": true
        },
        "operation": "insert",
        "collection": "contact"
      },
      "credentials": {
        "mongoDb": {
          "id": "smjByRgHnSMlBLZV",
          "name": "MongoDB account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b78fa066-00f8-48c5-979e-d8da9d6c1593",
      "name": "编辑字段",
      "type": "n8n-nodes-base.set",
      "position": [
        432,
        80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "4569533b-44c5-4c3b-a0af-0634e2ffba4c",
              "name": "name",
              "type": "string",
              "value": "={{ $json.Name }}"
            },
            {
              "id": "f828360a-e1f6-46ed-856a-0768efdb073e",
              "name": "last_name",
              "type": "string",
              "value": "={{ $json[\"Last Name\"] }}"
            },
            {
              "id": "46322cb3-5080-4902-b5dc-110e1047054c",
              "name": "email",
              "type": "string",
              "value": "={{ $json.Email }}"
            },
            {
              "id": "a5648b31-50f9-4022-b5bb-0a9d43027341",
              "name": "phone",
              "type": "string",
              "value": "={{ $json[\"Phone Number\"] }}"
            },
            {
              "id": "3cc35bbb-3ce1-4bab-bb1c-a3983a1ed2d1",
              "name": "submitted_at",
              "type": "string",
              "value": "={{ $json.submittedAt }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e1312e0c-f824-4d5b-bcc4-86ffbe82c0ea",
      "name": "便签11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        384,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 198,
        "height": 240,
        "content": "## 3"
      },
      "typeVersion": 1
    },
    {
      "id": "dca3c2c8-5ed0-48ef-a1ee-692fdd66e08b",
      "name": "便签12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 198,
        "height": 240,
        "content": "## 5"
      },
      "typeVersion": 1
    },
    {
      "id": "8ba91a2e-f86a-49c9-8ea4-c0117669b0a3",
      "name": "表单结束",
      "type": "n8n-nodes-base.form",
      "position": [
        880,
        80
      ],
      "webhookId": "097a2720-67d1-4954-80fb-b7220928e5a1",
      "parameters": {
        "options": {},
        "operation": "completion",
        "completionTitle": "✅ Message Sent Successfully",
        "completionMessage": "Thank you for reaching out! Your message has been received, and our team will get back to you shortly. We appreciate your interest and look forward to connecting with you."
      },
      "typeVersion": 2.3
    },
    {
      "id": "2b610b7f-5477-47e2-adc8-db94db46ed0f",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        656
      ],
      "parameters": {
        "color": 5,
        "width": 688,
        "height": 144,
        "content": "### 4. MongoDB 节点(插入文档)"
      },
      "typeVersion": 1
    },
    {
      "id": "8021689f-b978-434f-bd21-480518b89868",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        848
      ],
      "parameters": {
        "color": 5,
        "width": 688,
        "height": 144,
        "content": "### 5. 表单结束节点"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5dbb6364-7f28-46f5-b95e-46e7cd558a69",
  "connections": {
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Insert documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert documents": {
      "main": [
        [
          {
            "node": "Form Ending",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Pattern": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Validate Pattern",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 潜在客户开发, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量16
分类2
节点类型6
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Samuel Heredia

Samuel Heredia

@sheredia

I like to believe that I can contribute to creating a better world with the developments I make :)

外部链接
在 n8n.io 查看

分享此工作流