I can't agree with forcing the browser to submit the form. I my opinion, any form submission should be left entirely up to the user.
However, if you just want to remove the survey from an inactive computer you can add something like this to the end of
template.js.
(adjust the first 5 variable as necessary)
This will:
- Start an "alert" timer on page load
- When the "alert" timer expires a dialog is popped up and a "redirect" timer is started
- When the "redirect" timer expires the page is redirected
- Closing the dialog will stop the "redirect" timer and restart the "alert" timer
- Any activity in the form (click, key-up, paste, change) will restart the "alert" timer
Code:
$(document).ready(function(){
var txtAlertMessage = 'Anyone there? Do you want to continue?';
var txtCloseButton = 'Continue';
var redirectURL = location.pathname.split('index.php')[0];
var timeToAlert = 300; // In seconds
var timeToRedirect = 5; // In seconds
// Page timeout action
function pageTimeout() {
window.location = redirectURL;
}
// Alert Timer
var alertTimer;
function startAlertTimer() {
alertTimer = setTimeout(function() {
$('.custom-dialog-1').dialog('open');
},timeToAlert*1000);
}
function stopAlertTimer() {
clearTimeout(alertTimer);
}
function restartAlertTimer() {
clearTimeout(alertTimer);
startAlertTimer();
}
startAlertTimer();
// Redirect Timer
var redirectTimer;
function startRedirectTimer() {
redirectTimer = setTimeout(function() {
pageTimeout();
},timeToRedirect*1000);
}
function stopRedirectTimer() {
clearTimeout(redirectTimer);
}
function restartRedirectTimer() {
clearTimeout(redirectTimer);
startRedirectTimer();
}
// Insert the alert dialog
var timeoutDialog = '<div class="custom-dialog-1"> \
<div class="text">'+txtAlertMessage+'</div> \
<div class="buttons"> \
<button class="close" type="button" value="close">'+txtCloseButton+'</button> \
</div> \
</div>';
$(timeoutDialog).dialog({
autoOpen: false,
open: function( event, ui ) {
startRedirectTimer();
//IE 10 z-index hack
$('.ui-widget-overlay').css('z-index', Number($('.ui-widget-overlay').css('z-index')) - 2);
},
close: function( event, ui ) {
stopRedirectTimer();
restartAlertTimer();
},
width: 400,
modal: true,
resizable: false,
draggable: false,
closeOnEscape: true,
dialogClass: 'timeout-dialog'
});
$('.timeout-dialog button').click(function() {
$('.custom-dialog-1').dialog('close');
});
// Listener for activity
$('#limesurvey').on('click keyup paste change' ,function(event){
restartAlertTimer();
});
});