Documentation

FormEasy docs

Everything the library does, how to call it from any stack, and fixes for the usual snags. The library is about 200 lines, so you can also just read it.

Start here

Quick start#

FormEasy turns a Google Sheet into an endpoint you can POST JSON to. Each submission is written as a new row and, if you like, emailed to you. Here's the whole setup:

  1. 1Create a Google Sheet (sheets.new) and open Extensions → Apps Script.
  2. 2Next to Libraries click +, paste the Script ID below, click Look up, pick version 2 and keep the identifier FormEasy.
  3. 3Replace the code in Code.gs with the function below.
  4. 4Deploy → New deployment → type Web app, execute as Me, access Anyone. Authorize, then copy the Web app URL.
  5. 5POST JSON to that URL from your site, app or script.
Code.gs
function doPost(req) {
  FormEasy.setEmail('[email protected]'); // Where notifications go
  return FormEasy.action(req); // Always last, always returned
}

Try it before you build it

There's a live demo form that writes to a public demo Sheet, and the snippet builder makes code for your own fields.

Reference

API reference#

Call the setters inside doPost, then return FormEasy.action(req). Everything except action is optional.

MethodWhat it doesDefault
setSheet(name)Writes to the tab with this exact name. The tab must already exist.The first tab
setEmail(address)Sends an HTML summary of each submission to this address. Leave it out for rows only.No email
setSubject(text)Subject line of the notification email.New submission using FormEasy
setFormHeading(text)Heading at the top of the notification email.Form submission - FormEasy
setFields(...names)The keys to read from the JSON, in column order. Writes the header row (capitalised) plus a Date column.'name', 'email', 'message'
setRecaptcha(secretKey)Rejects submissions without a valid reCAPTCHA token (v2 or v3) under the key gCaptchaResponse.Off
action(req)Validates, writes the row, sends the email and returns a JSON response. Always call it last and return its result.Required

Order matters

Call setSheet before setFields: setFields writes the header row to whichever tab is selected at that moment.

How rows are written

Each submission is inserted as row 2, right under the header, so the newest is always on top. Only the keys listed in setFields are saved; anything else in the JSON is ignored. The last column gets the date and time in the form November 23, 2026 9:41:07 AM. Notification emails set reply-to from the email field, so Reply goes to the sender.

Client side

Sending data#

Send a POST whose body is a JSON string, with the header Content-Type: text/plain;charset=utf-8. Pick your stack:

const FORM_URL = 'https://script.google.com/macros/s/<DEPLOYMENT_ID>/exec';

async function submit(data) {
  const res = await fetch(FORM_URL, {
    method: 'POST',
    // text/plain keeps it a simple request, so there's no CORS preflight
    headers: { 'Content-Type': 'text/plain;charset=utf-8' },
    body: JSON.stringify(data),
  });
  return res.json(); // { status: 'OK', message: 'Data logged successfully' }
}

submit({
  name: 'Ada Lovelace',
  email: '[email protected]',
  message: 'Hello from my static site!',
}).then(console.log);

Why text/plain?

Apps Script web apps don't answer CORS preflight requests. A text/plain POST is a "simple request", so browsers send it without a preflight. The body is still JSON. From servers and scripts, follow redirects (curl -L, or the default in most HTTP libraries): Google answers through a redirect.

A plain HTML form post won't work

A form with action="…" and no JavaScript sends URL-encoded data, which FormEasy rejects with Invalid JSON format. Use the HTML snippet above: it reads the form with FormData and posts JSON.

Client side

Responses & errors#

FormEasy always answers with JSON containing status and message. Check status === 'OK'.

statusmessageMeans
OKData logged successfullyThe row was written (and the email sent, if set).
errorInvalid JSON formatThe body wasn't a JSON string. See Sending data.
errorInvalid sheet nameNo tab matches setSheet. Names are exact, including case and spaces.
errorreCAPTCHA verification under key 'gCaptchaResponse' is required.reCAPTCHA is on but the request had no token.
errorPlease tick the box to verify you are not a robot.Google rejected the token: missing tick, expired or reused.

If you get an HTML page instead of JSON, the script itself failed or isn't authorized. Open Executions in the Apps Script sidebar to see the error.

Spam protection

reCAPTCHA#

FormEasy checks Google reCAPTCHA tokens with Google's siteverify API before writing anything. Both v2 (the "I'm not a robot" checkbox) and v3 (invisible) tokens work. Register your site at google.com/recaptcha/admin to get a site key (public, for your page) and a secret key (private, for Apps Script).

v2 checkbox

Code.gs
function doPost(req) {
  FormEasy.setEmail('[email protected]');
  FormEasy.setRecaptcha('YOUR_SECRET_KEY');
  return FormEasy.action(req);
}
index.html
<head>
  <script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>

<form id="contact-form">
  <!-- your fields -->
  <div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY"></div>
  <button type="submit">Send</button>
</form>
submit.js
const data = Object.fromEntries(new FormData(form));
data.gCaptchaResponse = grecaptcha.getResponse(); // token from the checkbox

v3 invisible

Same setRecaptcha call in Apps Script. On the page, load the script with your site key and ask for a token on submit:

index.html
<script src="https://www.google.com/recaptcha/api.js?render=YOUR_SITE_KEY"></script>

<script>
  form.addEventListener('submit', (event) => {
    event.preventDefault();
    grecaptcha.ready(async () => {
      const data = Object.fromEntries(new FormData(form));
      data.gCaptchaResponse = await grecaptcha.execute('YOUR_SITE_KEY', { action: 'submit' });
      // …then POST data as usual
    });
  });
</script>

Keep the secret secret

The secret key only ever goes in Apps Script. Your page only needs the site key.

Patterns

Recipes#

Several forms, one deployment

Send a form key with each submission and choose the tab and fields in doPost. Create the tabs first.

Code.gs
function doPost(req) {
  let form = '';
  try {
    form = JSON.parse(req.postData.contents).form;
  } catch (e) {} // FormEasy.action answers invalid JSON for you

  if (form === 'waitlist') {
    FormEasy.setSheet('Waitlist');
    FormEasy.setFields('email', 'plan');
  } else {
    FormEasy.setSheet('Contact');
    FormEasy.setEmail('[email protected]');
  }
  return FormEasy.action(req);
}
submit.js
// Each form sends its own name along with its fields
submit({ form: 'waitlist', email: '[email protected]', plan: 'Pro' });

A honeypot field

A free extra layer against simple bots, with or without reCAPTCHA.

index.html
<!-- Hidden from people and screen readers, tempting to bots -->
<input name="company_website" tabindex="-1" autocomplete="off" aria-hidden="true"
  style="position:absolute; left:-9999px" />
Code.gs
function doPost(req) {
  let data = {};
  try {
    data = JSON.parse(req.postData.contents);
  } catch (e) {}

  // People never see this field, so only bots fill it in.
  // Answer OK so the bot moves on, but write nothing.
  if (data.company_website) {
    return ContentService.createTextOutput(JSON.stringify({ status: 'OK' }))
      .setMimeType(ContentService.MimeType.JSON);
  }

  FormEasy.setEmail('[email protected]');
  return FormEasy.action(req);
}

Rows only, for high-volume data

Logs, sensor readings and analytics events don't need an email each. Leave out setEmail.

Code.gs
function doPost(req) {
  // No setEmail: rows only, so high-volume data never touches the email quota
  FormEasy.setSheet('Readings');
  FormEasy.setFields('device', 'temp', 'humidity');
  return FormEasy.action(req);
}

Send people to a thank-you page

submit.js
const result = await res.json();
if (result.status === 'OK') {
  window.location.href = '/thanks'; // your own thank-you page
} else {
  alert(result.message);
}

Make the Sheet work for you

Once rows arrive, it's a normal Google Sheet: share it with your team, add filters and charts, use conditional formatting, or add an Apps Script trigger to act on new rows.

Apps Script

Deploying & updating#

Authorizing the first time

When you deploy, Google asks you to authorize the script and may show Google hasn't verified this app. That screen appears for any personal script, even one you write yourself. Choose Advanced → Go to your project → Allow. The script runs as you, so it can write to your Sheet and send email from your account.

Updating without changing the URL

  1. 1Edit and save your code.
  2. 2Open Deploy → Manage deployments and click the pencil on your existing deployment.
  3. 3Under Version choose New version, then Deploy.

New deployment = new URL

New deployment creates a different URL. Use Manage deployments to keep the one your site uses.

Updating the library

In Apps Script, click FormEasy under Libraries and pick the newest version, then publish a new version of your deployment.

Good to know

Limits#

FormEasy itself adds no limits. Google's Apps Script and Sheets limits apply, including:

LimitFree Google accountGoogle Workspace
Notification email recipients100 a day1,500 a day
Script run time6 minutes per run6 minutes per run
Simultaneous runs3030
Cells per spreadsheet10 million10 million

Google can change these; the current numbers are on the Apps Script quotas page. A single submission takes about a second, so run time is rarely an issue. Files can't be uploaded through FormEasy: store them elsewhere and send a link.

Fixes

Troubleshooting#

›CORS error in the browser console

Use Content-Type: text/plain;charset=utf-8, check that the deployment's access is Anyone, and that the URL ends in /exec.

›The response is an HTML page, not JSON

The script threw an error or needs authorizing. Open Executions in Apps Script to read the error, and redeploy after fixing it.

›My code changes don't show up

Deployments run a fixed version. Publish a New version via Manage deployments.

›Rows land in the wrong tab

Call setSheet with the exact tab name, and before setFields.

›Some values are blank

Keys in your JSON must match the names in setFields exactly, including case.

›The header row changed

When setFields doesn't match row 1, FormEasy rewrites the header. Older rows keep their old column order, so start a new tab when you change fields.

›No notification emails

Check the address in setEmail, your spam folder, and the daily email quota. Rows are written before the email is sent.

Still stuck? Open an issue on GitHub with the response you got and your doPost code (without secrets).

Releases

Changelog#

  1. Version 2 August 22, 2022

    • Added Google reCAPTCHA support to stop spam submissions.
    • New submissions are written to the top rows instead of the bottom.
  2. Version 1 June 22, 2022

    • First public release: submissions to Google Sheets via Apps Script.
    • Customisable fields, email subject and email heading.
    • Email notifications to the address of your choice.

Full notes are in CHANGELOG.md. Want to help shape the next version? Read the contributing guide.