I want to get a text from a html form but I didn't find out how to recover the data. This worked fine in an older version of the form, and also when I reprogrammmed it due to deprecation of UI methods). But now it does not function anymore. I reprogrammed it and the resulting code shows the html form but I can't recover the data. When I click OK form does not react (when I click Exit, form closes).
Mi code is
Code GS
var authorName='';
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('IM@ICHOS Menu')
.addItem('Identifiy User', 'showDialog')
.addSeparator()
.addSubMenu(ui.createMenu('Verification')
.addItem('Show User', 'showUser'))
.addToUi();
}
function showDialog() {
try {
var ss = SpreadsheetApp.getActiveSpreadsheet();
html = HtmlService.createHtmlOutputFromFile('InputAuthor');
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Input author name');
ss.toast('Author ->'+authorName);
}
catch (event) {
Browser.msgBox("Error report of [Monitored dialogues]/showDialog: " + event.message);
}
}
//getValuesFromForm
function getValuesFromForm(form){
try {
authorName = form.authorName;
return;
}
catch (event) {
Browser.msgBox("Error report of [Software and Data Status]/getValuesFromForm: " + event.message);
}
}
InputAuthor.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<b>Identifies Author</b><br /><br />
Please, input your eMail(without domain) to allow proper identification of changes authorship.<br />(message from ICHOS/IM Team)<br />
<br />
<b>Input User</b>: <input id="authorName" name="authorName" type="text" />
<input onclick="formSubmit()" type="button" value="OK" />
<input onclick="google.script.host.close()" type="button" value="Exit" />
</form>
<script type="text/javascript">
function formSubmit() {
google.script.run
.getValuesFromForm(document.getElementById('InputAuthor'));
.withFailureHandler(myFailureFunction)
.withSuccessHandler(mySuccessFunction)
}
function mySuccessFunction() {
alert("Done!");
google.script.host.close();
}
function myFailureFunction(argError) {
alert("There was an error: " + argError.message);
google.script.host.close();
}
function getValuesFromForm(form){
try {
authorName = form.authorName;
return;
}
catch (event) {
Browser.msgBox("Error report of [Software and Data Status]/getValuesFromForm: " + event.message);
}
}