How to send an HTML form to Airtable
Airtable is a good home for form submissions you want to work through. Each one becomes a record you can assign, give a status and link to a client, and the team sees it in a view instead of an inbox. Airtable's own for
Airtable is a good home for form submissions you want to work through. Each one becomes a record you can assign, give a status and link to a client, and the team sees it in a view instead of an inbox.
Airtable's own forms do this, but they live on Airtable's page. If the form is already on your site, in plain HTML or React or Astro, something has to take the post and call Airtable's API. This guide does it two ways: a small Cloudflare Worker you run yourself, and a form backend that does the mapping for you.
Why the browser can't call Airtable directly
Airtable's API takes a personal access token. Anything in your page's JavaScript is public, so a token in the browser lets anyone write records to your base, as many as they like, and read them too if the token has read access.
So the form posts to a small server of yours, and only that server holds the token.
Option A: a Cloudflare Worker
Set up the table
Create a table with three columns: Name and Email (single line text) and Message (long text). Then create a token at airtable.com/create/tokens:
- Add one scope:
data.records:write - Under Access, add only this base
- Create it and copy the token
You also need the base ID. Open the base and it's the part of the URL that starts with app.
The Worker
// Form field name β Airtable column name
const COLUMNS = { name: "Name", email: "Email", message: "Message" };
const ALLOWED_ORIGIN = "https://example.com";
export default {
async fetch(request, env) {
const headers = { "Access-Control-Allow-Origin": ALLOWED_ORIGIN };
if (request.method !== "POST") return new Response("Method not allowed", { status: 405 });
const form = await request.formData();
// Honeypot filled in: answer OK so the bot learns nothing.
if (form.get("_gotcha")) return Response.json({ ok: true }, { headers });
const fields = {};
for (const [field, column] of Object.entries(COLUMNS)) {
const value = String(form.get(field) ?? "").trim().slice(0, 5000);
if (value) fields[column] = value;
}
if (!fields.Email) return Response.json({ ok: false }, { status: 400, headers });
const res = await fetch(
`https://api.airtable.com/v0/${env.AIRTABLE_BASE_ID}/${encodeURIComponent(env.AIRTABLE_TABLE)}`,
{
method: "POST",
headers: {
Authorization: `Bearer ${env.AIRTABLE_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ records: [{ fields }], typecast: true }),
},
);
if (!res.ok) {
console.error("Airtable error", res.status, await res.text());
return Response.json({ ok: false }, { status: 502, headers });
}
return Response.json({ ok: true }, { headers });
},
};
Change ALLOWED_ORIGIN to your site. Then deploy it and store the token as a secret, so it never sits in your code:
npx wrangler deploy
npx wrangler secret put AIRTABLE_TOKEN
Add AIRTABLE_BASE_ID and AIRTABLE_TABLE (the table's name) as variables in wrangler.jsonc or the dashboard.
typecast: true tells Airtable to convert the text it gets, so 42 lands in a number column and a date string in a date column. Without it, every value has to match its column type exactly.
The form
The Worker answers with JSON, so post with fetch() and show the thank-you message on your own page. A FormData body doesn't need a CORS preflight, which keeps the Worker short.
<form id="contact">
<input name="name" placeholder="Name" required>
<input name="email" type="email" placeholder="Email" required>
<textarea name="message" placeholder="Message" required></textarea>
<!-- Honeypot: hidden from people, bots fill it in -->
<div aria-hidden="true" style="position:absolute; left:-9999px">
<input type="text" name="_gotcha" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Send</button>
</form>
<script>
const form = document.getElementById("contact");
form.addEventListener("submit", async (event) => {
event.preventDefault();
const res = await fetch("https://your-worker.your-subdomain.workers.dev", {
method: "POST",
body: new FormData(form),
});
form.replaceWith(res.ok ? "Thanks, we got your message." : "Something went wrong. Please try again.");
});
</script>
Submit it once and a record should show up in the table.
Where it breaks
-
Column names have to match. Rename Email to Email address in Airtable and every submission fails with
UNKNOWN_FIELD_NAMEuntil you change the Worker. Airtable also accepts field IDs (fldβ¦) instead of names, and those survive a rename. -
Select columns. With
typecast, a value that isn't an option yet gets added as a new one, if the token's owner can change the base. If they can't, the whole record is refused. -
Rate limits. Airtable allows 5 requests a second per base and answers
429above that. The Worker doesn't retry, so a burst loses submissions. - The monthly allowance. Airtable's Free plan includes 1,000 API calls a month. A bot posting to your form can use that up in an afternoon, and then nothing saves until next month.
- No second copy. When Airtable is down or refuses a record, the Worker logs an error and the submission is gone. Fixing that means a queue and retries.
- Spam. The honeypot only stops simple bots. Written sales pitches get through and become records, and each one counts against your API calls.
For a personal site with a few messages a week, the Worker is fine. Past that, most of the work is in the list above.
Option B: a form backend that maps the fields
With Formkove, the form posts to a Formkove URL. Each submission is saved, checked for spam, emailed to you and added to Airtable as a record.
Point the form at Formkove. Create a form at app.formkove.com and use its endpoint as the action. No server and no script, and the _gotcha honeypot is on by default.
<form action="https://app.formkove.com/api/forms/YOUR_FORM_ID/submissions" method="POST">
Connect Airtable. Create a token with the data.records:write and schema.bases:read scopes and add your base under Access. Then, in the form's Integrations, click Connect Airtable, paste the token and pick the base and table. The token is stored encrypted and never shown again.
Map the fields. Formkove lists the table's columns. For each one you pick a form field, a Formkove value (Submitted at, Submission ID, Sentiment, Tags, Spam score, File links) or a fixed text like Website. Columns with the same name as a form field are filled in for you, so Full Name matches full_name. Rename a column in Airtable and you fix it with Edit mapping, without touching code. Click Send test to add a sample record.
Send only some submissions. Describe your tags in plain words on the form's AI & Spam page (for example, sales-lead: wants a quote, a price or to hire us), then add a routing rule to the Airtable connection:
-
Tag has any of
sales-lead
Now the table only gets leads, and you can map Sentiment and Tags to their own columns. Rules can also test any form field, like budget is greater than 5000. Email isn't routed: you still get every real submission by email.
What comes with it:
- Spam held back before anything reaches Airtable, so it doesn't use your API calls. It's kept in your dashboard for 30 days in case one was a real message.
- Every submission saved, even when Airtable is down or refuses a record. Failed deliveries are retried and listed in Delivery history with the reason.
- Select columns handled. If Airtable refuses a new select option, Formkove saves the record without its select columns instead of losing it.
- Rate limits on every form: 10 a minute and 30 an hour per IP address.
Airtable, tags and routing are on the Pro and Agency plans, and Free accounts get them on their first 50 submissions (pricing). Setup details are in the Airtable docs.
Originally published on formkove.com.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.