How to Create an HTML Form and Link It with Google Spreadsheet
Creating an HTML form and linking it to a Google Spreadsheet can be incredibly useful for collecting data, such as survey responses, contact information, or customer feedback, directly from your website. This guide will walk you through the steps to set up an HTML form and connect it to a Google Spreadsheet, ensuring that all submitted data is automatically saved.
Step 1: Setting Up the Google Spreadsheet
Before we dive into the HTML coding, you’ll need to create a Google Spreadsheet that will store the data submitted through your form.
Create a New Spreadsheet:
- Go to Google Sheets.
- Click on Blank to create a new spreadsheet.
- Name your spreadsheet appropriately (e.g., "Form Responses").
Set Up the Headers:
- In the first row, add headers that correspond to the data you want to collect. For example:
NameEmailPhone NumberMessage
- These headers will match the form fields you’ll create later.
Publish the Spreadsheet:
- Click on File > Share > Publish to the web.
- Choose Entire Document and Web page in the drop-down menus, then click Publish.
Your download will be ready in 5 seconds...
- Use Notepad++ or visual studio
- Copy the code and paste it into the notepad++ or visual studio
Code Link
Step 3: Creating the Google Apps Script
To link your form to the Google Spreadsheet, you’ll need to use Google Apps Script.
- Open Google Apps Script:
- In your Google Spreadsheet, click on Extensions > Apps Script.
- Delete any existing code in the script editor and paste the following code
2.Save and Deploy the Script:
- Save the script with a meaningful name.
- Click on Deploy > Test deployments, then click Deploy.
- Set Execute as to your account and Who has access to Anyone.
- Copy the Web App URL provided; this is the URL you’ll use in your HTML form’s
scriptURLvariable.
3.Update the Spreadsheet ID:
- Replace
'YOUR_SPREADSHEET_ID'in the script with your actual Google Spreadsheet ID. You can find this ID in the URL of your spreadsheet, between/d/and/edit.
Step 4: Integrating the HTML Form with the Google Spreadsheet
'YOUR_GOOGLE_SCRIPT_URL_HERE' with this URL.


