Submit an HTML Form to Google Sheets

Submit an HTML Form to Google Sheets

Submit an HTML Form to Google Sheets
Hey, It's super cool guys. First Create an HTML  file or form. its super easy Create a html file if dont know check it my video.

so when you create html file

method="post" autocomplete="off" name="hello-sheet"> Enter this code in form start section ..

and definityley check your button type="submit" name="submit" value="Send message"   .. ok now you are done ..

Now copy script code - 


        

and paste before .. body section ...

When you done the process  go to google sheet... and create google sheet 
type your data name - like, name, email , etc if done ..  go tool > script editor 

var sheetName = 'Sheet1'
		var scriptProp = PropertiesService.getScriptProperties()

		function intialSetup () {
		  var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet()
		  scriptProp.setProperty('key', activeSpreadsheet.getId())
		}

		function doPost (e) {
		  var lock = LockService.getScriptLock()
		  lock.tryLock(10000)

		  try {
			var doc = SpreadsheetApp.openById(scriptProp.getProperty('key'))
			var sheet = doc.getSheetByName(sheetName)

			var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]
			var nextRow = sheet.getLastRow() + 1

			var newRow = headers.map(function(header) {
			  return header === 'timestamp' ? new Date() : e.parameter[header]
			})

			sheet.getRange(nextRow, 1, 1, newRow.length).setValues([newRow])

			return ContentService
			  .createTextOutput(JSON.stringify({ 'result': 'success', 'row': nextRow }))
			  .setMimeType(ContentService.MimeType.JSON)
		  }

		  catch (e) {
			return ContentService
			  .createTextOutput(JSON.stringify({ 'result': 'error', 'error': e }))
			  .setMimeType(ContentService.MimeType.JSON)
		  }

		  finally {
			lock.releaseLock()
		  }
		}

Ok .. Now go initialsetup then deploy... 
but wait .. check the video properly if Not working or 
if remove some code due to  any types of issue 
Check the link  

congratulations ..