jamiewilson/form-to-google-sheets

How to redirect it to homepage instead of showing this in new tab.

FutureUltron opened this issue · 1 comments

{"result":"success","row":2}

How to redirect it to homepage instead of showing this in new tab.
Screenshot 2023-07-01 at 00 12 10

What worked for me was:

  1. set the Web App access/auth, "Who has access" to Anyone.
    you can do this in appscript by clicking Deploy, Manage Deployments, edit

  2. then in your html file after closing tag.

<script>
window.addEventListener("load", function() {
  const scriptURL = '<YOUR SCRIPT URL>'
  const form = document.getElementById('id of your form');
  form.addEventListener("submit", function(e) {
    e.preventDefault();
    const data = new FormData(form);
    fetch(scriptURL, {
      method: 'POST',
      body: data,
      mode: 'no-cors', // unsure if this is needed since access changed to anyone
    })
    .then(() => {
    window.top.location.href = 'your page url';
    })
  });
});
</script>