I have a Google Apps Script Webapp which serves a simple html form. My Apps Script function processData(formdata)
receives the form data as a Blob as described here . After I process the data I want to return another simple html page to the user. I tried the naive approach like this:
function processData(formdata){
// do something with the data
process(formdata);
return HtmlService
.createHtmlOutputFromFile('html/final')
}
However the page is always blank after the user submits the data. How can I give the user a proper response?
This is my second approach as suggested by @Cooper. I added it in the html and used the withSuccessHandler
but the page remains white after submitting:
<!DOCTYPE html>
<html>
<head>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script>
function updateUrl() {
var div = document.getElementById('msg');
div.innerHTML = "<h1>Thanks for the submission</h1><p>You should be hearing from us soon</p>";
}
function handleFormSubmit(formObject) {
google.script.run.withSuccessHandler(updateUrl).processForm(formObject);
}
</script>
</head>
<body>
<div id="msg"></div>
<div class="container">
<h1>FORM insert data</h1>
<form id="myForm" onsubmit="handleFormSubmit(this)">
<div class="form-group">
<label for="nameInput">enter your name</label><br />
... and so on
[Edit]
I now added the preventFormSubmit
function as described in the example by Cooper. Now after submitting the message is shown. However the complete form stays on the page where I would prefere to only have the message be shown.
That said it seems that it is not easy to just show another html. Does that mean it is not possible to have a more complex webapp which require more html sides with Google Apps Script?
Thanks for the submission
You should be hearing from us soon
"` and then you can change the style with `$('#msg').css('display','block');` of course you'll have to include JQuery on your page as well. Fortunate Google host all of those types of things for people to use. But you can also do it with straight javascript. – Cooper Jun 29 '20 at 17:31