Sending website form entries to a spreadsheet automatically

There are three roads for every enquiry from a form on your site to end up in a spreadsheet: a Google Form in place of your form, a small Google script (Apps Script) that receives the data, or a workflow in n8n. The second is the lightest and needs no server of your own. It is the one explained here.

Which of the three to pick

Road What you need Advantage Limit
Google Forms A Google account. Answers link to a sheet with no code. The form is Google’s, not your site’s.
Apps Script A Google account and a form of your own. Keeps your site’s form and writes to the sheet. You write a small script, and must protect it.
n8n A VPS with n8n installed by you. Does more than store: notifies, confirms to the customer, filters. It is third-party software you maintain. See do you need a VPS for n8n?

The Apps Script road, step by step

1 Prepare the sheet. In the first row, the column headings: date, name, e-mail, message. Create a sheet just for this, not the one you use for anything else.
2 Open the sheet’s script editor (in the extensions menu, “Apps Script”) and write a doPost(e) function. It reads e.parameter and adds a row with appendRow. It ends by returning a plain text reply.
3 Protect it with a key. At least one hidden field, such as key, which the script compares with a value only you know. Without it, anyone who discovers the address can fill your sheet with junk.
4 Publish it as a web app (the deploy option), running as you and open to anyone with the link. Google gives you an address. Keep it.
5 Make your server call that address. In PHP, once you have validated the form, send the fields with curl_init, CURLOPT_POST and http_build_query, and follow redirects (CURLOPT_FOLLOWLOCATION). That way the address never reaches the visitor’s browser.
6 Test with a fake entry and confirm the row appears. Then test with the wrong key and confirm it is refused.
This is a sheet of personal data. Names, e-mails and messages from customers sit on a third-party service. Limit who can open the sheet, say on the form where the data goes, and delete what you no longer need. See personal data protection on your website.

If your site’s form does not even send an e-mail, fix that first: a contact form that actually reaches your inbox. The sheet should be an extra record, not the only place the enquiry exists.

Always send the e-mail and the sheet. If Google changes a rule or the script’s address stops working, you lose no enquiries. You can also store the time and the page of origin on each row to see where contacts come from.

Need a site with forms that work? See the hosting plans.

See the plans

SEE ALSO

Connecting n8n to Google Sheets

A contact form that actually reaches your inbox

What a webhook is, and how to test one with curl

Hosting plans

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $6.59/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?