Here's how I got it done without any Javascript, JQuery or Ajax:
The way to implement is to use the <meta http-equiv="refresh" content="<Time In Seconds>;URL=newurl.com">
tag. The <Time In Seconds>
is a parameter to be included in that tag.
The <meta http-equiv="refresh"
tag can be placed anywhere in the code file - Not necessarily at the top, not necessarily at the bottom, just anywhere you wish to place it.
The beauty of this tag is that it does NOT stop the execution of the code at itself. It will still execute ALL the code (including that below it) till the <Time In Seconds>
remains a non-zero value.
And it will itself get executed ONLY when the <Time In Seconds>
value lapses.
Hence, the way to get it going is to use a PHP parameter for $remainingtime
in seconds, and have it updated to the remaining survey time each time a question of the survey is answered by the user.
<meta http-equiv="refresh" content="'.<?php echo $remainingtime; ?>.';URL=submitbeforetimeend.php" />
Essentially, if the survey is to be completed in 20 minutes max, then start with 1200 as $remainingtime for Q1. If user takes 50 seconds to answer Q1, update remaining time in the same/next form page for Q2 to 1950, and so on.
If the user finishes only Q15 by the time that $remainingtime
reaches zero, then the meta tag statement will get executed, and it will get redirected to URL=submitbeforetimeend.php
.
This page will have the function to record the users' answers upto Q15, which serves the purpose without use of any client-side script.
No Javascript, JQuery or Ajax. All user input remains hidden & secure in PHP or whatever variables.
Still Open - The above solution fixes the problem of the user NOT completing the survey in the stipulated time. It still leaves one particular scenario (out of purview of original question) about recording the inputs submitted so far (till Q15) in case the user decides to close the browser window/tab (maybe user feeling bored of several questions)?
Any suggestions/answers on similar approach that can be implemented for recording inputs if the user closes the browser (without any scripts, of course)? Feel free to add to the answers. Thanks!