Tech With Galvan
Back to Articles
AutomationApr 15, 2029 • 4 min read

How to Connect Your Website Form to WhatsApp

Connect your website contact form to WhatsApp — instant lead alerts, no backend required. With HTML, JavaScript, and Python options.

Galvan
Galvan

Founder & Creator

Introduction

When a customer fills out your contact form, every minute of delay reduces the chance of conversion. Connecting your form to WhatsApp sends you an instant notification — so you can reply in seconds, not hours.

This post shows you 3 ways to connect your website form to WhatsApp.

Method 1: WhatsApp Click-to-Chat (no backend, simplest)

The simplest approach — redirect the form submission to WhatsApp.

<form id="contact-form" onsubmit="sendToWhatsApp(event)">
    <input type="text" id="name" placeholder="Your Name" required>
    <input type="email" id="email" placeholder="Your Email" required>
    <textarea id="message" placeholder="Message" required></textarea>
    <button type="submit">Send via WhatsApp</button>
</form>

<script>
function sendToWhatsApp(e) {
    e.preventDefault();
    const name = document.getElementById('name').value;
    const email = document.getElementById('email').value;
    const message = document.getElementById('message').value;
    
    const text = `Hi! My name is ${name}.\nEmail: ${email}\nMessage: ${message}`;
    const whatsappUrl = `https://wa.me/919876543210?text=${encodeURIComponent(text)}`;
    
    window.open(whatsappUrl, '_blank');
}
</script>

Pros: Zero backend, instant, free Cons: Opens WhatsApp (customer must have it), doesn’t save to a database

Method 2: Form → WhatsApp via Zapier/Make (no-code)

Zapier workflow

Trigger: New submission in Formspree (or your form tool)
    ↓
Action: Send WhatsApp message via WATI/Twilio
    Message: "New lead! Name: {name}, Email: {email}, Phone: {phone}. Message: {message}"
    To: Your WhatsApp number

Make workflow

Same as Zapier but with more flexibility (conditional logic, data transformation).

Setup (Zapier)

  1. Create a Zapier account
  2. Trigger: Formspree → New Submission
  3. Action: WhatsApp by WATI → Send Message
  4. Map fields: name, email, phone, message
  5. Test and turn on

Pros: No code, saves to form tool’s database, instant alerts Cons: Requires Zapier account (free tier: 100 tasks/month)

Method 3: Custom form + Python backend (full control)

Frontend (HTML)

<form id="contact-form">
    <input type="text" id="name" placeholder="Your Name" required>
    <input type="email" id="email" placeholder="Your Email" required>
    <input type="tel" id="phone" placeholder="Phone">
    <textarea id="message" placeholder="Message" required></textarea>
    <button type="submit">Send</button>
</form>

<script>
document.getElementById('contact-form').addEventListener('submit', async (e) => {
    e.preventDefault();
    const data = {
        name: document.getElementById('name').value,
        email: document.getElementById('email').value,
        phone: document.getElementById('phone').value,
        message: document.getElementById('message').value,
    };
    
    const res = await fetch('/api/contact', {
        method: 'POST',
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify(data),
    });
    
    if (res.ok) {
        alert('Thank you! We\'ll be in touch shortly.');
        document.getElementById('contact-form').reset();
    } else {
        alert('Something went wrong. Please try WhatsApp directly.');
    }
});
</script>

Backend (Python + FastAPI)

from fastapi import FastAPI, Request
import requests, os

app = FastAPI()

@app.post("/api/contact")
async def handle_contact(request: Request):
    data = await request.json()
    
    # Validate
    if not data.get("name") or not data.get("email"):
        return {"error": "Name and email required"}, 400
    
    # Save to Google Sheets
    save_to_sheets(data)
    
    # Send WhatsApp alert
    send_whatsapp_alert(data)
    
    # Send email notification
    send_email_notification(data)
    
    return {"success": True}

def send_whatsapp_alert(lead):
    url = "https://live-server-XXXX.wati.io/api/v1/sendSessionMessage"
    message = f"🔔 New Lead!\n\nName: {lead['name']}\nEmail: {lead['email']}\nPhone: {lead.get('phone', 'N/A')}\nMessage: {lead['message']}"
    payload = {"whatsappNumber": os.environ["YOUR_PHONE"], "messageText": message}
    headers = {"Authorization": f"Bearer {os.environ['WATI_API_KEY']}"}
    requests.post(url, json=payload, headers=headers)

def send_email_notification(lead):
    import resend
    resend.api_key = os.environ["RESEND_API_KEY"]
    resend.Emails.send({
        "from": "Leads <[email protected]>",
        "to": [os.environ["YOUR_EMAIL"]],
        "subject": f"New lead: {lead['name']}",
        "html": f"<p>Name: {lead['name']}<br>Email: {lead['email']}<br>Phone: {lead.get('phone', 'N/A')}<br>Message: {lead['message']}</p>",
    })

Step 4: Save to Google Sheets (optional)

import gspread
from google.oauth2.service_account import Credentials
from datetime import datetime

def save_to_sheets(lead):
    creds = Credentials.from_service_account_file("service_account.json",
        scopes=["https://www.googleapis.com/auth/spreadsheets"])
    gc = gspread.authorize(creds)
    sheet = gc.open("Leads").sheet1
    sheet.append_row([
        lead["name"], lead["email"], lead.get("phone", ""),
        lead["message"], datetime.now().isoformat(), "New"
    ])

Method comparison

Method Setup time Cost Customization Saves data? Best for
Click-to-Chat 5 min Free Low No Simple sites
Zapier/Make 15 min Free tier Medium Yes (form tool) No-code
Custom (FastAPI) 1-2 hours Free (hosting) Full Yes (Sheets/DB) Full control

Best practices

1. Respond fast

  • Aim for under 5 minutes for WhatsApp leads
  • Set up instant alerts (see WhatsApp Lead Alerts)
  • Use auto-reply if you can’t respond immediately

2. Capture enough info

  • Name, email, phone, message (minimum)
  • Add: budget, timeline, service interest (optional but helpful)

3. Reduce friction

  • Don’t ask for too much information upfront
  • Use a simple form (3-4 fields max)
  • Make the submit button obvious

4. Add spam protection

  • Honeypot field (hidden input that bots fill)
  • reCAPTCHA (Google’s spam protection)
  • Rate limiting (max 5 submissions per IP per hour)

5. Test on mobile

  • 60%+ of form submissions are on mobile
  • Ensure the form is responsive and easy to use on small screens

Common mistakes

  • No mobile optimization — forms that are hard to use on phones lose leads
  • Too many fields — 8+ fields reduce conversion by 50%. Keep it to 3-4.
  • No confirmation — users don’t know if their message was sent. Show a success message.
  • No fallback — if the form fails, provide a WhatsApp/phone number
  • No spam protection — you’ll get flooded with bot submissions

Key Concepts

  • Click-to-chat = WhatsApp link that opens a chat with pre-filled message
  • Webhook = HTTP callback for real-time events
  • Honeypot = hidden field that bots fill but humans don’t
  • reCAPTCHA = Google’s spam protection
  • Formspree = form backend service (handles submissions)

What to Try Next

FAQ

Click-to-chat vs form submission — which is better?

Click-to-chat = instant, but requires the customer to have WhatsApp and compose a message. Form submission = structured data, but has a delay. Use click-to-chat for quick inquiries; forms for detailed requests. Or use both (form + “Or WhatsApp us” link).

Does click-to-chat work on desktop?

Yes — it opens WhatsApp Web on desktop. But conversion rates are lower on desktop (people prefer forms). Mobile conversion is much higher for click-to-chat.

How do I handle form spam?

Add a honeypot field (hidden input) and check server-side. Use reCAPTCHA v3 (invisible). Rate-limit submissions per IP. These three measures eliminate 99% of spam.

Can I use this with WordPress?

Yes — use a plugin like WPForms or Contact Form 7 with custom JavaScript, or add the click-to-chat link directly. For the custom backend approach, use a WordPress plugin that supports webhooks. See Capture Leads Into Google Sheets.