A contact form can tell you who wrote in. The workflow below tells you which inquiries to open first. It turns budget, timeline, and contact details into a score you can explain by reading one Code node.
You'll build this in an existing n8n instance using four built-in nodes. You can test every route in the editor without CRM, Slack, email, or AI credentials.
1. Receive the form submission
Add a Webhook node. Set HTTP Method to POST, Path to lead-intake, and Respond to Immediately. The immediate response acknowledges receipt. Check the execution to see whether the lead passed validation and where it was routed. n8n Webhook documentation
2. Validate and score the payload
Connect the Webhook to a Code node named Validate & Score Lead. Select JavaScript and Run Once for All Items, then paste this code.
const FREE_DOMAINS = new Set([
'gmail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', 'icloud.com', 'aol.com', 'proton.me', 'protonmail.com'
]);
const DISPOSABLE_DOMAINS = new Set([
'mailinator.com', 'guerrillamail.com', 'tempmail.com', '10minutemail.com', 'yopmail.com', 'trashmail.com', 'sharklasers.com'
]);
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
return $input.all().map((item) => {
const raw = item.json.body && typeof item.json.body === 'object' ? item.json.body : item.json;
const honeypot = String(raw.website_hp || raw._gotcha || '').trim();
const name = String(raw.name || raw.fullName || '').trim();
const email = String(raw.email || '').trim().toLowerCase();
const company = String(raw.company || '').trim();
const message = String(raw.message || raw.notes || '').trim();
const source = String(raw.source || raw.utm_source || 'website').trim();
const timeline = String(raw.timeline || 'exploring').trim().toLowerCase();
const budgetNum = Number(String(raw.budget || '0').replace(/[^0-9.]/g, '')) || 0;
const domain = email.includes('@') ? email.split('@')[1] : '';
const reasons = [];
if (honeypot) reasons.push('honeypot_triggered');
if (!EMAIL_RE.test(email)) reasons.push('invalid_email');
if (DISPOSABLE_DOMAINS.has(domain)) reasons.push('disposable_domain');
if (!name) reasons.push('missing_name');
const isValid = reasons.length === 0;
const isBusinessEmail = Boolean(domain) && !FREE_DOMAINS.has(domain) && !DISPOSABLE_DOMAINS.has(domain);
let score = 0;
if (isValid) {
score = 20;
if (isBusinessEmail) score += 25;
if (budgetNum >= 5000) score += 30;
else if (budgetNum >= 1500) score += 15;
if (timeline === 'asap' || timeline === 'this_month' || timeline === 'immediate') score += 20;
if (company && message.length >= 15) score += 5;
score = Math.min(100, score);
}
const tier = !isValid ? 'rejected' : score >= 70 ? 'hot' : score >= 40 ? 'warm' : 'nurture';
return {
json: {
isValid,
rejectionReasons: reasons.join(','),
leadId: `LD-${Date.now().toString(36).toUpperCase()}`,
receivedAt: new Date().toISOString(),
name,
firstName: name.split(/\s+/)[0] || 'there',
email,
domain,
isBusinessEmail,
company: company || 'Not provided',
budget: budgetNum,
timeline,
source,
message,
score,
tier
}
};
});
The score starts at 20 for a valid submission. An email domain outside the two lists adds 25 points. A budget of at least $1,500 adds 15 points, or 30 points at $5,000 and above. An urgent timeline adds 20 points. A company name and a trimmed message of at least 15 characters add 5 points.
Treat these weights as rules for queueing work. A domain outside the free-provider list is only a proxy for a business email, and the format check can't confirm mailbox ownership. For this example, send budgets in US dollars with US-style formatting. The parser strips currency symbols and other characters, so normalize and validate currency upstream if your form accepts multiple formats.
3. Filter first, then route
Connect the Code node to an IF node. Add a Boolean → is true condition and set its value to the expression {{ $json.isValid }}. Leave the false output disconnected. You can still inspect rejectionReasons in the Code node's output.
Connect the true output to a Switch node in Rules mode. For both rules, use the expression {{ $json.tier }} as the left value and String → is equal to as the comparison.
| Right value | Output | Score |
|---|---|---|
hot |
Rename to Hot | 70 or more |
warm |
Rename to Warm | 40–69 |
| No match | Set Fallback Output to Extra Output | Below 40 after the IF gate |
Keep the IF node before the Switch. Otherwise, a rejected item would also reach the fallback output. You can leave all three outputs disconnected while testing and inspect the item in the Switch output for each branch. n8n Switch documentation
4. Test all four paths
In the Webhook node, select Test URL and click Listen for Test Event. In a Bash-compatible shell, run the request below with your full Test URL.
curl -i -X POST 'http://localhost:5678/webhook-test/lead-intake' \
-H 'Content-Type: application/json' \
-d '{"name":"Taylor Example","email":"taylor@example.org","company":"Example Studio","budget":"$6,500","timeline":"asap","message":"We need help automating client intake.","website_hp":""}'
Start listening again before each request. For each row below, start from the original payload and change only the fields listed. The scores are expected outputs for these sample inputs.
| Changes to the original payload | Expected score | Where to look |
|---|---|---|
| None | 100 | Switch → Hot |
Email taylor@gmail.com, budget 2000, timeline next_quarter
|
40 | Switch → Warm |
Email taylor@gmail.com, budget 500, timeline exploring
|
25 | Switch → Extra Output |
Set website_hp to filled
|
0 | IF → false, with honeypot_triggered in the Code output |
If the request gets an HTTP success response but the Switch has no data, inspect the IF output first. A filled honeypot or invalid address should stop the item there. If the Test URL returns a webhook registration error, start listening again and check that the URL contains /webhook-test/.
Once the branches behave as expected, decide what each route should do. For example, send hot leads to a review queue and save warm and nurture leads for a later pass. If you insert a storage node before the Switch and its output replaces the input fields, update the Switch to read the tier from Validate & Score Lead using {{ $('Validate & Score Lead').item.json.tier }}.
AI disclosure: This tutorial was drafted with AI assistance.
Top comments (0)