October 25, 2024
Chicago 12, Melborne City, USA
HTML

How would i fetch the data from a google apps script web app html form?


Recently I’ve been working with google apps script, google sites, and google sheets hand in hand. My most recent leg of the project has been trying to take input from the google sites website and input into a google sheet using a google apps script webapp. I’ve been doing some research on how to do this and I’ve been told I can fetch the data like i would in normal html however when i do so and output it to the sheet nothing pops up there and since the web app is an detached from the editor i cant view any sort of console log. Any idea how i would be able to make this take the form output and set it to a variable i can then insert into a google sheet?

So far I’ve been able to get my html form created and outputted into the web app so that when executed the form does pop up and once the submit button is pressed the page does load into a new blank one, however there’s no output in the sheet or data in the execution log history. I do see a new cursor in the sheet which confirms the opening and selection of the cell of want but no data what so ever ends up in there. Here is my code so far:

Javascript:

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('register'); 
}

function submitForm(e) {
  var userInputForm = e.document.querySelectorAll('userInput');
  var userInputData = userInputForm.innerHTML;
  console.log(userInputData);
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName(ROSTER);
  var range = sheet.getRange("A3:A3");
  range.setValues(userInputData);
}

HTML:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <form id="myForm">

    <input type="text" id="userInput" placeholder="Enter Username">
    <input type="text" id="discordInput" placeholder="Enter Discord Username">

    <button type="submit">Register</button>

    </form>
  </body>
</html>



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video