title: Google Apps Script HTMLService display confirmation page after form submit
body: <p>I created a web app form using Google Apps Script and the HTMLService.</p>
  
  <p>It is a one-page form with a submit button at the bottom. </p>
  
  <p>When submitted, the form validates whether the data input into the form is valid, and if valid, it logs the form data to a spreadsheet.</p>
  
  <p>That all works so far.</p>
  
  <p>I now need the user to be sent to a confirmation page, and the confirmation page needs to be able to have parameters passed to it (to display certain information on the confirmation page).</p>
  
  <p><strong>main.gs:</strong></p>
  
  <pre><code>function doGet(e) {
  
    var template = HtmlService.createTemplateFromFile('form');
    return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
  
  }
  
  function processFormSubmission(formData) {
  
    Logger.log('starting processPoRequest');
    Logger.log('po: ' + JSON.stringify(formData, null, 2));
    // code for appending data to sheet here
  
  }
  </code></pre>
  
  <p><strong>form.html:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;form id="form1" name="form1"&gt;
  
    &lt;label for="info" id="info_label"&gt;Info&lt;/label&gt;
    &lt;input id="info" name="info" type="text"&gt;
  
    &lt;input class="btn" id="button" onclick="onClickFunctions(document.getElementById('form1'))" type="submit" value="Submit"&gt;
  
  &lt;/form&gt; 
  
  &lt;script&gt;
  
  function onClickFunctions(formData) {
  
    console.log('starting onClickFunctions');
  
    var allDataValid = validateForm(formData);
  
    if (allDataValid === true) {
  
      google.script.run.withSuccessHandler().processFormSubmission(formData);
  
    }
  
  }
  
  function validateForm(form) {
  
    console.log('starting validateForm');
  
    var errors = 0;
  
    var element = document.getElementById('info');
    if (!form.info) { element.classList.add("validation_error"); errors++; if (errors === 1) element.focus(); }
    else element.classList.remove("validation_error");
  
    if (errors &gt; 0) return false;
    else            return true;
  
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>confirmation.html:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;?!= confirmationMessage ?&gt;
  </code></pre>
  
  <p>I don't know what to put in <code>.withSuccessHandler()</code> to make it so that the user is brought to the confirmation page. </p>
  
  <p>I've Googled this extensively and found these results on Stack Overflow, and each one suggests a different solution, but none of them actually include complete working code for a solution: </p>
  
  <p>Possible solutions using doPost:</p>
  
  <p><a href="https://stackoverflow.com/questions/18668828/send-form-by-email-and-track-responses-in-spreadsheet/18669532#18669532">Send form by email and track responses in spreadsheet</a></p>
  
  <p><a href="https://stackoverflow.com/questions/12907122/htmlservice-dopost-with-google-docs-form">HtmlService doPost With Google Docs Form</a></p>
  
  <p><a href="https://stackoverflow.com/questions/11720092/htmlservice-dopost">HtmlService doPost</a></p>
  
  <p>I messed around with doPost but I couldn't figure out how to get it to be invoked, and I couldn't find any official documentation in the <a href="https://developers.google.com/apps-script/guides/html/" rel="nofollow noreferrer">HTMLService docs</a>. </p>
  
  <p>Possible solution using the link to the web app in an a href: </p>
  
  <p><a href="https://stackoverflow.com/questions/11280978/href-in-htmlservice">href in HtmlService</a></p>
  
  <p>If my button was a link that looked like a button, I'm not sure how I would execute the form validation function when the link is clicked.</p>