Submitting form using Google script API method
To submit data using the google.script.run
API methods, add onclick
property to the Submit button:
<input type="submit" value="SUBMIT" onclick="google.script.run.postFormDataToSheet(this.parentNode);" /> <!-- this.parentNode is the 'form' element -->
Create the postFormDataToSheet
function as shown here:
function postFormDataToSheet(e){ // Replace with your spreadsheet's ID. var ss = SpreadsheetApp.openById("spreadsheet's id"); var SheetResponses = ss.getSheetByName("Responses"); // Create a 'Responses' sheet if it does not exist. if(!SheetResponses){ SheetResponses = ss.insertSheet("Responses"); } SheetResponses.appendRow([e.places]); }
To show Form submission result or error message, insert the postData
function in a separate <script>
tag and add success and failure handlers with a callback function as shown here:
<script> function postData(form){ google.script.run .withSuccessHandler...