Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to avoid form resubmission when browser refresh clicked!

Status
Not open for further replies.

micjohnson

Programmer
Nov 9, 2000
86
US
In ColdFusion or Javascript, how to i avoid form resubmission when refresh button cliked.

Thanks

micJ
 
Move away from the form action page. After the user clicks the "submit" button, it will go to the action page, then you should take the user to a "thank you" page after the form action has processed. That way, if they hit "refresh", they're on a different page and nothing will get submitted.




Hope This Helps!

ECAR
ECAR Technologies, LLC

"My work is a game, a very serious game." - M.C. Escher
 
ECAR's method is best, but if that doesn't work for the flow of your site you can check for common information in your form and your database before you do your insert.

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
I would go as far to say that Ecar's method should be a best practise, its certainly one that my developer's have to adhere to. We always, always, always do a cflocation after a database insert what you can then do is tack the unique ID to the url on the cflocation so you can pull the record back if needed for a confirmation page
 
I wouldn't go that far. I would say it depends on the nature of the site or application. Honestly it wouldn't hurt much to check for duplicate entries anyway. Double click a submit button for example, or click back to check something then submitting again, neither are "refreshing" the page but would cause double entries in your db. How many times has TT hung up causing double posts? I've had it happen a few times. less reciently, but it has happened and TT followes your "best practice".

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
why not check session for a var before submitting?

your form process could be surrounded by <cftransaction> tags and part of the transaction after the sql insert would be a <cfset> tag. If the form is submitted once set <cfset session.var1 = "wasSubmitted">

<cfif val var1 EQ "wasSubmitted">
Sorry your already submitted this form during your current session Please close your browser and visit this form agin to submit agin.
<cfelse>
Process form Stuff

<CFTRANSACTION>
SQL Stuff
<cfset session.var1 = "wasSubmitted">
</CFTRANSACTION>
<cfif>
 
TruthInSatire

On reflection I agree with you totally, it does depend on the the nature of the applications and as you pointed out it help to have another layer of checking (which incidentally we do - depending on the data being added). But for *my* team and the applications *we* work on, it is. :)
 
Thank you all.

Actually my action (Insert and Update process) is on the same page and i dont want to show any message like "Insert or Update Suuccessful".

So i used Ksea's method and it works well.

Thank you everybody for your great time.

Regards
micJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top