I need a script or a piece of code that can prevent refresh, because its making the data within the database really annoying... I tried to use the MVC model approach, but the requirements for this script differs away from that... So if any one has any code that prevents refresh of a page i will be grateful.. Thanks in advance
Preventing refresh
Moderator: General Moderators
Preventing refresh
Hi Guys/Girls,
I need a script or a piece of code that can prevent refresh, because its making the data within the database really annoying... I tried to use the MVC model approach, but the requirements for this script differs away from that... So if any one has any code that prevents refresh of a page i will be grateful.. Thanks in advance
I need a script or a piece of code that can prevent refresh, because its making the data within the database really annoying... I tried to use the MVC model approach, but the requirements for this script differs away from that... So if any one has any code that prevents refresh of a page i will be grateful.. Thanks in advance
-
chadhaajay
- Forum Newbie
- Posts: 2
- Joined: Sat Jul 28, 2007 4:45 am
Hello, why don't you just check for the data duplication so that duplicate data records are not saved inthe database. Usually you cna use the email_address check to see if the email is already saved then prompt the user for duplicate email_address error so that if they keep on pressing refresh button again and again, it doesn't store the data in the database because it is duplicate entry.
Sincerely,
Ajay Chadha (Director)
Chadha Software Technologies
Sincerely,
Ajay Chadha (Director)
Chadha Software Technologies
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
The database shouldn't need to do anything. You need to place restrictions on your users... All of them.ghadacr wrote:Thanks for the suggestion, but the data that is being passed does not contain email address's... Also i dont want the database to handle too much of the vaildation side of things, i'm running alot of SP's....
- The Phoenix
- Forum Contributor
- Posts: 294
- Joined: Fri Oct 06, 2006 8:12 pm
You don't understand.ghadacr wrote:Hmm yeah i get it but, the script i got has mutiple processes running concurrently, so the redirection does sound good, but it wont solve the issue in hand.. Thanks for the suggestion though..
Right now, your script upon receiving a post, processes (sends the data to the database). Instead, it should be redirecting users to a results page, then processing. That way, if they hit refresh, its refreshing the redirect - not the processing.
Its the Post->Redirect->Get pattern, and its designed specifically for the issue you are facing - even in a multiple process application.
Other alternatives (that can be defeated trivially):
- Use javascript to set the submit button onclick to unavailable/greyed out
- Use a db cache to detect whether that statement has been sent to the db in the last minute (and then don't send it)
- Use a unique key on the database so that you cannot send the same data to the db repeatedly
- Use a unique key on the processing side to prevent multiple submissions by a single user.
But all of those ignore the key issue, which is that you are processing multiple submits on refresh. The correct solution is to use the PRG pattern, as it completely changes the processing of that form to make refreshes inert.