Script not working in New Google Sites

400 views
Skip to first unread message

NewToScripts22

unread,
Jul 23, 2019, 4:16:17 PM7/23/19
to google-apps-sc...@googlegroups.com
Hi,

A script embedded in new google sites was working fine until recently. In my code, the goGet method is used to load the page (which works fine). In this doGet function, there is also a line to set the action variable : 

function doGet(e){ 
    
  var html= HtmlService.createTemplateFromFile('index')
  html.action = ScriptApp.getService().getUrl();
  return html.evaluate;

}



And action is a variable in the index.html as seen below:

<form id="keyForm" onsubmit="handleFormSubmit(this)" action="<?= action ?>" method="post"> 


The "action" here is to open a new page 'Thanks.html' on form submit.

function doPost(e) {
  var html= HtmlService.createTemplateFromFile('Thanks.html');
   return html.evaluate;
}


The new page opens when I test the script as a standalone webApp but has suddenly stopped opening when script embedded in google site is run. So, when I click Submit, all the data is saved as intended but the Thanks.html does not open.

Can someone help understand the reason for this sudden issue and also help with a solution?

Clark Lind

unread,
Jul 24, 2019, 6:40:35 PM7/24/19
to Google Apps Script Community
If you hit F12 and open your browser's DevTools, are there errors in the console tab? Any errors should give you a clue what is going on. This sounds like a possible CORS problem maybe. (wild guess).

IAlex

unread,
Jul 25, 2019, 4:04:35 PM7/25/19
to Google Apps Script Community
As I can understand HTTP the browser calls page via GET (not POST).

If you need to get the content from a file you have to do something like this

/**
 *
 * @param {GoogleAppsScript.Events.DoPost} e
 */

function doPost(e) {
 
var html = HtmlService.createTemplateFromFile('Thanks.html');
  html
.name = e.parameter.name;
 
return html.evaluate().getContent();
}


It seems to me that your example is not working. Or you did not bring enough information.

- Alex

Trevor Scanlan

unread,
Oct 1, 2019, 8:05:31 PM10/1/19
to Google Apps Script Community
What about else about the form element would have to change?

I have tried all of this and nothing works to get a confirmation page to load after my form element submits the record

ChiefChippy2

unread,
Oct 2, 2019, 12:06:57 PM10/2/19
to Google Apps Script Community
Try : Update the web app to a new version 
Testing it again with standalone web app; if it doesn't work check if e.parameter.name is defined ( in doPost )

Maybe form submit isn't allowed in new google sites ( some iframe issues? )
Reply all
Reply to author
Forward
0 new messages