user1015214
user1015214

Reputation: 3081

how to prevent a user from pressing backspace/back arrow

I have a string of surveys, one after the other. It seems that after one survey, some people are pressing backspace to go back to the previous survey and then resubmitting it with new information. How can I stop this? I am assuming that I need some sort of Javascript script.

I have found this Preventing backspace to go back from the current form

but it doesn't seem to help if someone is doing it on purpose, which might be the case.

Upvotes: 0

Views: 190

Answers (3)

shanehoban
shanehoban

Reputation: 870

I can see how it can be done in PHP by creating a $_SESSION, and updating it as each form is completed.

At the beginning of each page simply check that the session correlates with the correct survey.

I'll try and give an example.

First page

$_SESSION['status'] = 1;  // allowed to view survey 1
if($_SESSION['status'] != 1){
 header('Location: /page' . $_SESSION['status'] . '.php');
 exit();
}

// your survey
// clicks submit
// goes to 2nd page

.... 2nd page (2nd survey)

$_SESSION['status'] = 2; // updates the status to show is on the 2nd page
if($_SESSION['status'] != 2){
     header('Location: /page' . $_SESSION['status'] . '.php');
     exit();
    }


// your survey
// clicks submit
// goes to 3rd page.. etc

Upvotes: 0

Jayesh
Jayesh

Reputation: 53345

I assume you are tracking user's progress in survey on server (through cookie). If the user has proceeded to the page N in the survey and you don't want him to go back and modify his response on page N-1, then you can present him back with the page N even though he tries to access N-1 page. That will take care of user getting back to the N-1 page by pressing back button (something he/she can do even if you block backspace button)

Upvotes: 0

psx
psx

Reputation: 4048

Do not break the back button. This breaks the browser HCI rules.

To do this properly you need to assign a unique ID to each instance of a survey being taken. Then, when a survey is being started, check that the ID has not been submitted before.

Upvotes: 5

Related Questions