How I can pass/get data from the html form in Google apps script? I was trying many times but still can't get the right code. I hope someone can help me here with this problem.
Code.gs
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('Index');
}
function getValuesFromForm(form) {
var firstname = form.lastname,
lastname = form.firstname,
ss = SpreadsheetApp.openById('1XvrQFzVTlCqtB6HGggeGKraaLrd_8wdw6rAGVNVxYC0');
var sheet = ss.getSheets()[0];
sheet.appendRow([firstname, lastname]);
}
Index.html
<form>
First name: <input id="firstname" name="firstName" type="text" />
Last name: <input id="lastname" name="lastName" type="text" />
<input onclick="google.script.run.getValuesFromForm(this.form)" type="button" value="Add Row" />
</form>
