Sending form data to a Google Sheet allows you to collect and organize information submitted through a web form directly into a spreadsheet. By integrating Google Apps Script with your HTML form, you can capture user input and append it to a specific sheet within your Google Sheets document. This process streamlines data collection, enabling efficient analysis and management of responses.
let sheet = SpreadsheetApp.openByUrl(SheetLink);
let sheetName = sheet.getSheetByName('Sheet1');
function doPost(e){
let data = e.parameter;
sheetName.appendRow([data.COURSE, data.NAME, data.EMAIL, data.PHONE, data.ADDRESS, data.MESSAGE, data.GENDER]);
return ContentService.createTextOutput('data saved');
}
let form = document.querySelector("#form");
let url 'DEPLOY URL';
form.addEventListener("submit", (e) => {
e.preventDefault();
init()
let formData = new FormData(form);
fetch(url, {
method: "POST",
body: formData,
})
.then((res)=>res.text())
.then((data)=>{
//DO STUFF HERE
})
.catch((error) => {
console.error("Error:", error);
});
});