Home FAQ New Contact Mock Test About

Add a form to your site and receive the data free

Send form responses straight into a Google Sheet using a small Google Apps Script. No server, no paid form service, and it works on any host.

How the pieces connect

You need a Google account and any website where you can paste HTML.

HTML form

The form on your website sends the answers with a small fetch call.

Apps Script

A free Google script receives the data as a web app and writes it.

Google Sheet

Every submission becomes a new row, with a timestamp.

Create the Google Sheet

This sheet stores every response.

1

Make a new sheet

Open sheets.new and name it, for example Website form responses. Keep the first tab named Sheet1.

2

Type the header row

In row 1 write these headers, one per column, exactly as shown. The script matches each header to a form field name, and capital letters matter.

ABCDE
Timestampnameemailphonemessage
Want another field? Add a header with the same name as the input's name attribute, and add that input to the form.

Add the Apps Script code

The script lives inside the sheet and runs on Google's servers.

3

Open the script editor

In the sheet press Extensions, then Apps Script. A new tab opens with a file named Code.gs.

4

Replace the code

Select everything in Code.gs, delete it, and paste this:

const SHEET_NAME = 'Sheet1'; const MAX_LEN = 2000; function doPost(e) { const lock = LockService.getScriptLock(); try { lock.waitLock(10000); if (e.parameter.website) return reply({ result: 'success' }); // honeypot: bots fill this const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME); const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]; const row = headers.map(function (h) { if (h === 'Timestamp') return new Date(); return clean(e.parameter[h]); }); sheet.appendRow(row); return reply({ result: 'success' }); } catch (err) { return reply({ result: 'error', message: String(err) }); } finally { lock.releaseLock(); } } function clean(v) { v = String(v || '').slice(0, MAX_LEN); return /^[=+\-@]/.test(v) ? "'" + v : v; // stops spreadsheet formula injection } function reply(obj) { return ContentService.createTextOutput(JSON.stringify(obj)) .setMimeType(ContentService.MimeType.JSON); }

Press the save icon, and name the project if asked. If your tab is not called Sheet1, change SHEET_NAME at the top.

Deploy it as a web app

This gives you the public URL your form will post to.

5

Create the deployment

  1. Press Deploy, then New deployment.
  2. Press the gear next to Select type and choose Web app.
  3. Set Execute as to Me.
  4. Set Who has access to Anyone.
  5. Press Deploy.
6

Allow access

Press Authorize access and choose your Google account. Google may warn that the app is not verified, because it is your own script. Press Advanced, then Go to your project (unsafe), and allow it.

7

Copy the web app URL

Copy the address that ends in /exec. This is your form endpoint. Anyone who has it can submit data, so do not share it for any other purpose.

After you change the script later, use Deploy, Manage deployments, the pencil icon, New version, then Deploy. The URL stays the same, but old code keeps running until you do this.

Add the form to your site

Paste both pieces into your page where the form should appear.

8

The HTML

<form id="contactForm"> <input type="text" name="name" placeholder="Your name" required> <input type="email" name="email" placeholder="Email" required> <input type="tel" name="phone" placeholder="Phone"> <textarea name="message" placeholder="Message" required></textarea> <input type="text" name="website" tabindex="-1" autocomplete="off" style="display:none"> <button type="submit">Send</button> <p id="formMsg" role="status"></p> </form>

The hidden website field is a trap for spam bots. Real visitors never see or fill it.

9

The JavaScript

Place this just before the closing body tag, and replace the placeholder with your /exec URL from step 7.

<script> const SCRIPT_URL = 'PASTE_YOUR_WEB_APP_URL_HERE'; const form = document.getElementById('contactForm'); const msg = document.getElementById('formMsg'); form.addEventListener('submit', async function (e) { e.preventDefault(); const btn = form.querySelector('button'); btn.disabled = true; msg.textContent = 'Sending...'; try { const res = await fetch(SCRIPT_URL, { method: 'POST', body: new FormData(form) }); const data = await res.json(); if (data.result !== 'success') throw new Error(data.message); form.reset(); msg.textContent = 'Thanks, we received your message.'; } catch (err) { msg.textContent = 'Something went wrong. Please try again.'; } finally { btn.disabled = false; } }); </script>
10

Test it

Open your page, fill the form and press Send. The message should appear, and a new row with the time and your answers should show up in the sheet within a few seconds.

Useful extras

Optional, but worth doing.

1

Get an email for every response

In Code.gs replace the line sheet.appendRow(row); with the block below, then deploy a new version. Apps Script asks for permission to send email the first time.

sheet.appendRow(row); MailApp.sendEmail({ to: Session.getEffectiveUser().getEmail(), subject: 'New form response', body: headers.map(function (h, i) { return h + ': ' + row[i]; }).join('\n') });

Daily email limits apply to free Google accounts, so this suits small forms.

2

Work with the data

  • Share the sheet with teammates using the Share button.
  • Download it with File, Download, then Excel or CSV.
  • Use filters, charts and formulas as in any sheet.
3

Respect your visitors

Tell people what you collect and why, for example with a short line under the form and a privacy page. Do not collect passwords, payment details or other sensitive data this way.

Fix common errors

Check the Apps Script Executions page first, because it lists every call and its error.

ProblemFix
Message says error and no row appearsOpen Executions in Apps Script. Check SHEET_NAME matches the tab name exactly.
Row appears but columns are emptyHeader names must match the input name attributes exactly, including capital letters.
Failed to fetch or CORS errorUse the URL ending in /exec, not /dev, and set access to Anyone. Send the data as FormData, as in the code above.
Edits to the script do nothingCreate a New version in Manage deployments. Saving alone does not update the live URL.
Authorization requiredRun the deployment steps again and approve the permissions on the Google screen.
Cells begin with an apostropheThat is intentional. The script protects against values that start with = + - or @.

Common questions

Is this really free?

Yes. Google Sheets and Apps Script cost nothing with a normal Google account. Apps Script has daily quotas, which are plenty for most small sites. See Google's Apps Script quotas page for current numbers.

Does it work on GitHub Pages, Cloudflare and Vercel?

Yes. The form only needs HTML and JavaScript, so any host works, including the ones in the website host guide.

Is the data private?

The sheet is private to you unless you share it. The web app URL is public, so anyone who knows it can send a row. The honeypot and length limit reduce spam, but do not use it for sensitive data.

Can I collect file uploads?

Not with this setup. It stores text answers only. For files, use a Google Form with a file question or a different storage service.