Table of Contents
- About Google Sheets
- Benefits of Google Sheets
- How to insert/add data to google sheet from our website contact form
- 1. Setup project in google cloud console
- 2. Create google sheet and share it to the google developer console project's email
- Install and Configure the Google PHP API client
- 4. Code in our website to send contact form submission to google sheet
- Google sheet API code
- HTML contact form
- Jquery,Ajax to process our form
- PHP to send email and send records to google sheet
- Contact Request Submitted
About Google Sheets
Google Sheets is an online spreadsheet tool that's part of Google's Workspace suite. It lets you create, edit, and share spreadsheets in real-time, making it perfect for collaborative work. Multiple people can work on the same document at the same time, which is great for team projects and managing shared data. Google Sheets offers a variety of functions and formulas, just like traditional spreadsheet software, and it works seamlessly with other Google services like Google Drive, Google Docs, and Google Forms.
Benefits of Google Sheets
One of the major benefits of Google Sheets is its collaborative nature. Multiple people can work on the same spreadsheet at the same time, which makes it a great tool for teamwork and real-time data sharing. Additionally, Google Sheets automatically saves your work, so you never have to worry about losing your data. You can also access your spreadsheets from any device with an internet connection, making it a very flexible and convenient tool.
How to insert/add data to google sheet from our website contact form
1. Setup project in google cloud console
- Open google developer console Google Cloud Console
- Create new project
- Click on 'API & Services' -> 'Enable API & services' from left sidebar
- Search 'Google Sheet API' then enable it
- Click the 'Credentials' tab from the left side. then click 'Configure Consent Screen'. proceed all steps there
- Choose 'Google Sheets API' on 'Add or Remove Scopes' from above steps.
- Now create 'API Key' from left side 'Credentials' -> '+ Create Credentials'
- Then create Create 'OAuth client ID' from left side 'Credentials' -> '+ Create Credentials'
- Choose there 'Web Application' on 'Application Type'
- You can skip other selection like 'Authorized Domain'
- Create 'Service Account' from '+ Create Credentials'
- Finally Create 'KEYS' by clicking on email id shown under 'Service Account'
- There click 'Create New Key' from 'Add Key'. Choose Key type -> JSON
- After successful key creation it will download a json file containing all required information
- Keep the json file in safe place. We need it to put in our website project
2. Create google sheet and share it to the google developer console project's email
- Create google sheet using this link Create Google sheet
- Give a name to the sheet
- Click 'Share' on top right of the page
- Then put the email that you find in the downloaded json file mentioned in 'client_email'
Install and Configure the Google PHP API client
We need to install google PHP API client to integrate google sheet in our PHP website.
We also need to already have composer installed in our system.
If you don't have composer then visit composer official website to download and install.
Run below command in your PHP website root folder
After successfully running above command. It will create a folder 'vendor'
4. Code in our website to send contact form submission to google sheet
Now, we have done all the setups above. It's time to code on our website. I am using the core PHP website for this tutorial. So, I will guide you on this PHP website.
Google sheet API code
create a folder 'google_sheet' then a php file google_sheet.php in this folder. and put below code
Also put your downloaded json file in this folder and rename it to credentials.json . you can give any name but put the same name in above code in
Get the spreadsheet id from the spreadsheet url and put in our above code of
Also rename your sheet tab's name in below code . In my default name is 'Sheet1'
HTML contact form
I am using below HTML form for this tutoria, you can use the same for testing.
Jquery,Ajax to process our form
PHP to send email and send records to google sheet
Cretae ajax_submit.php and put below code
In this way we integrated google sheet API to send contact form submissions record to google sheet. I tried to guide in easy way. Hope you like our tutorial. I am Pawan Kumar , a freelance full stack web developer working since 2009. If you have any query, you can directly reach me via whatsapp no. +919999968096 . You can also support us for creating such informative and useful tutorials.