Finally, I found a way to add a timer to a google form, and yes, it forces the user to submit the form after a given time. It’s not like all the other plugins that will only close the form to not accept responses and the users that are in the process of filling in the form will lose their answers. Imagine the student who spends an hour answering the question to be only 1 minute late.
This solution will be very useful to educators that use Google Form to create online Quiz and need to add a time frame. I know, you can always check the time of the form submission manually and dismiss the ones that are late. But I don’t want to dismiss all the answers from the student just because he was 15 min late.
So, by implementing this solution you can set the deadline time and the script will make sure that the student can’t answer another question and can only submit the responses. Also, you don’t need to set a deadline, you can manually run the script and end the form.
Check the GIF to see how the solution works:
The solution is very easy to implement, to add a timer in google forms you just need to insert a few lines of code into the script editor and set up a trigger. But first, check the way you need to create or adapt your Form.
Google Form
In order for the timer script to work, you will need to create your form in, maybe, a little bit different way. Why I use the word maybe, it’s probably because you already use this kind of approach to create your google form quiz.
The way you need to create your form is to use a section for each question. So, if you are not already doing that, you must divide the questions into a separate sections, like in the image below:
This will not only make the solution work as intended, but it can make your form more readable and accessible. Especially if you enable the option “Show progress bar” from the “Presentation” tab in the form settings. Check here for other options available to Google Forms: Google Forms Settings
Now, the next thing is to insert the script.
The Script
The script is very simple, it contains only 8 lines of code, but when executed it changes the “After section” on all of the sections from “Continue to next section” to “Submit form”.
So, after the script executes, when the user presses the “Next” button it will submit the form or it will give him only the option to Submit the form. It would not be possible to enter a new section/question by pressing the Next button.
Here is the script:
function closeForm() {
var activeForm = FormApp.getActiveForm();
var sectionItems = activeForm.getItems(FormApp.ItemType.PAGE_BREAK);
for (var i=0; i < sectionItems.length; i++) {
var pageBreak = sectionItems[i].asPageBreakItem();
pageBreak.setGoToPage(FormApp.PageNavigationType.SUBMIT);
}
}
To insert the script, access the Script editor from the three-dot menu, and copy/paste the script there.
Now, you can run the script, just to accept the permissions and to check if it works. If everything is fine, the script will change all the sections to “Submit form”. To check this go back to your Form and see if all the sections are changed.
Notice
In order to use the Form after the script executes, you will need to change back the “After section” option to “Continue to next section”. In the last section “Script to Reset Form”, you can find a script to change them back automatically.
As I said earlier, this script will change all the sections to “Submit form”, so by executing it will stop the user to enter another question/section and force him to submit. So, to set up a time frame on your Form you just need to control the time of the execution of the script. There are two ways of doing this:
- Manually (by executing the script from the script editor) or
- By using a Time-driven trigger
If you decide to manually stop the Form, you can just execute the script at any time, hopefully, the time you told your students to send the form. The script will change all the sections to “Submit form” and the user will submit the form when he presses the “Next” button.
If you want the quiz/form to stop (script to execute) at a given time you will need to:
Add a time-driven trigger
Let’s say you have scheduled the exam tomorrow 8/24/2020, from 12:00 to 13:00 h, so you need to stop the exam on 8/24/2020 at 13:00. To set up this you will need to add a time-driven trigger to execute the script at a “Specific date and time”. So, in your script editor, click on the “Current project’s triggers” toolbar icon, and in the projects triggers window click on the button “+ Add trigger”. This will open a dialog box where you can set up your trigger.
Now, you will need to select “Time-driven” for the “Select event source” and select “Specific date and time” for the “Select type of time based trigger” option. And in the next text box enter the time when you would like your script to execute (stop the quiz). Check the image below:
Before entering the time, check the GMT if it’s for your time zone. If it’s not, you have to adapt for the time or you will need to change the GMT in your Google Calendar settings.
Click “Save” and that’s it, now you have a timer that will close the Google Form automatically.
Changing the Form/Quiz won’t affect the script, so you can go ahead and add more or remove some questions, but in order to be 100% efficient, always use sections for each question. And remember, when the script executes it changes all the sections, so to reuse your form or test it, you will need to change them back to “Continue to next section”
Script to Reset Form
On a suggestion from Adam Davis, a Diamond Product Expert on Google Docs community help forums, I have included an extra function that can help you reset back the Form so you don’t have to manually change the sections back to “Continue to next section”. This is very helpful if you have a lot of questions/sections in your form and changing them manually can get overwhelming.
Here is the script:
function resetForm() {
var activeForm = FormApp.getActiveForm();
var sectionItems = activeForm.getItems(FormApp.ItemType.PAGE_BREAK);
for (var i=0; i < sectionItems.length; i++) {
var pageBreak = sectionItems[i].asPageBreakItem();
pageBreak.setGoToPage(FormApp.PageNavigationType.CONTINUE);
}
}
Add this function after the previous one.
How to run this script
After you have run the previous script and you want to reuse your form just select this function “resetForm” from the dropdown list and press on the Run button. Check the image:
If you fund this solution useful and it’s working for you, drop me a comment and share it with your peers.