Auto submit google form after a time limit

I want to use app script in my Google form to automatically submit the form in 20 minutes if the user doesn't click on submit within 20 minutes. Anyway to implement this????


No, you cannot control the client-side of Google Forms, even if you add an Apps Script to it, because Apps Script runs on the server.

One possible solution is to serve your form as a Google Apps Script web app. At that point you can write client-side JavaScript and use window.setTimeout to submit the form after 20 minutes.

Here are some example files, Code.gs and quiz.html, that can provide a basic skeleton to start the web app. A blank project will have Code.gs as the default file, then you have to add File > New > HTML file to start the other file.

You can enter the id of any spreadsheet you own in the commented out lines in Code.gs to append the response into that spreadsheet. (You can also automate that process by creating a new spreadsheet as needed. Example of creating spreadsheet to hold data for Apps Script example can be found here.

// file Code.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("quiz");
}

function doPost(request) {
  if (request.answer) {
    console.log(request.answer);  // View > Execution transcript to verify this
    //var ss = SpreadsheetApp.openById(id).getSheetByName("Quiz Responses");
    //ss.appendRow([request.answer /* additional values comma separated here */ ]);
  }
}
<!DOCTYPE html>
<!-- file quiz.html -->
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <h1>Quiz</h1>
    <form>
      What is Lorem Ipsum?
      <input name="loremipsum" type="text"/>
      <button>Submit</button>
    </form>
    <script>
      const button = document.querySelector("button");
      const timeLimitMinutes = 1; // low number for demo; change to 20 for application
      const timeLimitMilliseconds = timeLimitMinutes * 60 * 1000;
      // For this demo we are not going to serve a response page, so don't try to.
      button.addEventListener("submit", submitEvent => submitEvent.preventDefault());
      // attach our custom submit to both the button and to the timeout
      button.addEventListener("click", submitForm)
      window.setTimeout(submitForm, timeLimitMilliseconds)

      function submitForm() {
        button.setAttribute("disabled", true);
        document.querySelector("h1").textContent = "Quiz submitted";
        // for demo: submitting just a single answer.
        // research Apps Script documentation for rules on submitting forms, certain values not allowed
        // consider a helper function `makeForm()` that returns a safe object to submit.
        const answer = document.querySelector("input").value;
        google.script.run.doPost({ answer });
      }
    </script>
  </body>
</html>

Test with Publish > Deploy as web app...