0
votes

when I click the button data submit. I am use this code can your help me to solve this problem

enter image description here

Code.gs

function onOpen() {
  SpreadsheetApp
      .getUi()
      .createMenu('Sidebar')
      .addItem('Contact Form', 'showSidebar')
      .addToUi();
}

function showSidebar() {
  var html = HtmlService
      .createTemplateFromFile('sidebar')
      .evaluate()
      .setTitle('Contact Form');
  SpreadsheetApp.getUi()
      .showSidebar(html);
}

and sidebar.html

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

<h3>First Name</h3>
<input type="text" name="firstname">   

<h3>Phone Number</h3>
<input type="text" name="phone">

<a href="#" onClick="return false;" class="fltr-button  animate">Submit</a>

</form>
</body>
</html>
1
Hi @ManishSinghal, Welcome to StackOverFlow. Kindly refer to this stackoverflow.help/support/solutions/articles/…. - JustCurious
And when I click the button data submit seems incomplete to me. Kindly tell us the issue you are facing in order to make us able to help you better. - JustCurious

1 Answers

1
votes
function showSideBar() {
  const html='<form><input type="text" name="firstname" placeholder="First Name" /><input type="text" name="phone" placeholder="Phone Number" /><br /><input type="button" value="Submit" onClick="google.script.run.processForm(this.parentNode);" /></form>';
  SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutput(html));
}

function processForm(obj) {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  sh.appendRow([obj.firstname,obj.phone])
}

Animation:

enter image description here