0

I've created form and on submit of form it'll redirect to success.html page which is in Google apps script. But i need to redirect to client side(i.e, same hierarchy level of index.html). Note: need the serialnum as well in succes page This is my index code:

<form method="POST" action="https://script.google.com/macros/s/xxx/exec">
        <label for="name">Name:</label>
        <input type="text" id="name" name="name" required />

        <label for="email">Email:</label>
        <input type="email" id="email" name="email" required />
        </form>

Code.js:

<script>
let MySheet = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/xxx");
let Demo2Sheet = MySheet.getSheetByName("Sheet1");

function doPost(e) {
    let Demo2 = e.parameter;

    var currentDate = new Date();
    var month = currentDate.toLocaleString("default", { month: "short" });
    var year = currentDate.getFullYear().toString().substr(-2);
    var serialNumber = "S" + month + year;

    Demo2Sheet.appendRow([Demo2.name, Demo2.email]);

    var template = HtmlService.createTemplateFromFile("success"); //success.html
    template.serialNumber = serialNumber;
    return template.evaluate();
}
Sandeep
  • 15
  • 6
  • Have it redirect to the doGet() endpoint and add a queryString that returns the content of the new page via HtmlService by decoding the parameters. – Cooper Mar 28 '23 at 19:15
  • From your request of `but a different scenario, can you answer this please. Here is my query: (stackoverflow.com/questions/75866808/…)` in my previous answer, I saw your this question. When I saw this question, I cannot understand your expected result. I think that this is due to my poor English skill. I apologize for this. But, I would like to support you. So, can I ask you about the detail of your question? First, I would like to correctly understand your question. – Tanaike Mar 29 '23 at 00:30
  • Sure @Tanaike, so basically in
    tag, I've included the POST and action. So here when I fillup form and click on submit it'll call dopost(e) function and captures the data in Google sheets. But user redirects to success.html(which I've created in apps script along with code.gs). Finally, instead of redirecting to success.html(in apps script) in need to redirect to local html(eg: href="/success.html")
    – Sandeep Mar 29 '23 at 03:57
  • Hi @Cooper, If you don't mind can you give a sort of example bcz I'm new to this apps script so. – Sandeep Mar 29 '23 at 04:02
  • Thank you for replying. I would like to support you. But, I have to apologize for my poor English skill, again. Unfortunately, from your reply, I cannot still understand your question. But I would like to try to understand it. When I could correctly understand it, I would like to think of a solution. I would be grateful if you can forgive my poor English skill. – Tanaike Mar 29 '23 at 04:15
  • So if you have understood my previous question, then the expected output is the same. (After form filling, Just need to redirect to the success HTML page.). Note: The success.html page should not be in apps script – Sandeep Mar 29 '23 at 04:50
  • This example does a similar thing in that it support multiplye pages in one webapp: https://stackoverflow.com/a/55770563/7215091 – Cooper Mar 29 '23 at 18:39

0 Answers0