Skip to content

A simple contact form built using HTML , CSS , Javascript & G-Script that uses google sheets as database.

Notifications You must be signed in to change notification settings

chiraag-kakar/contactme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

PRs Welcome

					😃Hit that ⭐ button to show some ❤️         

Contact Me

A simple contact form built using HTML , CSS , Javascript & G-Script. The collected data is saved in google sheets in real-time.

View Form | View Database

The Google script associated with the Google sheet is :

Note : Make sure the G-Script Project name is same as that of the Google Sheet Document. sheetName is the name of one sheet and not the entire document.

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()
		  }
		}

About

A simple contact form built using HTML , CSS , Javascript & G-Script that uses google sheets as database.

Topics

Resources

Stars

Watchers

Forks

Languages