PDA

View Full Version : How Return to URL Order Submitted From


gorilla1
05-04-2003, 04:57 AM
I have a number of order forms on several linked sites that call a common asp routine which checks the form and writes to database, etc, if good. On completion, the visitor is asked to hit the back button. I am finding that some orders are double submitted. Presumably, they hit the back button, which brings them back to the form with fields still checked out, and they must hit submit again, with the result that the order is processed again. Is there a way I can detect what url the form was submitted from so that I could do a metarefresh back to that url (which would clear the form)?

G

gorilla1
05-04-2003, 05:08 AM
Guess I could use request.servervariables("http_referer"), eh?

G

gorilla1
05-04-2003, 05:27 AM
What I really need then is to capture the back button and then send them to the referring url - that would be foolproof. I suppose that is a javascript question.

G

raf
05-04-2003, 10:44 AM
These are two problems/questions? Nor?
- how to redirect and show the empty form --> just a simple redirect. But i normally just display a "inserted succesfull" message with some possible links (like "updated form", "empty form", "other order", ...) Not sure what you're trying to do here
- how to prevent double submitting of a form.
1. Prevent the form-page from beeing cached (response.expires = -1000)
2. Redirect after inserting/updating to a confirmationpage or whatever page. (so they reload the confirmation page and not the form-page or asp-page that makes the insert/update
(response.redirect("thepage.asp")
3. For absolute safety, I use a flag. After the form is processed and the record is inserted/updated, i set a sessionvariable (like session("processed") = 1. On top of the page that processes the form (the same page in most cases) I check if the sessionvariable if 1. If so, i redirect and display a errormessage.
The session-variable is reset to 0 if they confirmed the order, or get back on some sort of startpage or whatever.

gorilla1
05-04-2003, 05:50 PM
Raf,
Thanks... Yes 3, is a good approach. Unfortunately, for various reasons, it will be a bit impractical, as it reuqires that I alter all the calling routines. I need to defend against the double update pretty much within the one script. It is, specifically, the refresh key that is probably the main problem.
G

gorilla1
05-04-2003, 08:44 PM
OK, I took care of at least javascript enabled visitors by using an onload on successful form completion that returns them to the referrer. So this means that if they hit back or refresh while the form confirmation is sitting in front of them they will be returned back to the form with all fields empty. Those with javascript disabled I have not yet addressed.


Update; Ah well, the onunload thing worked fine in a pws test environment, but does not prevent the duplication when uised on real world server. I have no clue why.
G

whammy
05-05-2003, 11:52 PM
You should be able to use a session variable for this as well - that will take care of most of the other people with javascript disabled... but depends upon cookies.

Maybe your best bet would be to see if they have already placed an order recently when the order is actually submitted by comparing to database values...