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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Avoid duplicate post and resubmission?

Status
Not open for further replies.

danieln4

Programmer
Apr 24, 2003
6
CA
I have 3 ASP pages (intro, forms, and a summary page). A user comes to the "intro" page and then to the "forms" page to enter his/her data to be submitted to an SQL and HP server. After the "submit" is clicked, the information get posted to the server and a reference number gets return on the "summary" page. The user then click on the IE "back" button and change some information on the form and resubmit.

How do I avoid this duplicate submission when clicking the "back" button and resubmitting? Should I drop some sort of cookies or session to keep track of the event that took place?
 
there is one very common way to prevent resubmission.
the steps are as easy as making pie. (ok, I've never made a pie but I hear it's easy) [wink]

when the user submits a form set a global value or hidden form field telling your script it was submitted.

validate this value you set to check to see if it is a certain value equaling the condition the form was submitted. if it was submitted per say a true value then you tell them and you do not allow the resubmission.

session variables are used (not recommended for high traffic situations)

most commonly hidden form fields and that is what I use and recommend


_________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
Onpnt,

How about as easy as falling down when inebriated? LOL

A star for you as I know this is an upcoming problem on an application that I am currently working on!

Everything is absolute. Everything else is relative.
 
[lol] me never. I can always manage to stay standing when I'm at that point. [lol]

thanks and glad this may help out

_________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
Thanks Onpnt. The process of how the page is currently working is that once you click on submit, it logs the transaction to my SQL and HP server and spits back a reference number which then redirect to the summary page.

So based on your sugestion upon using hidden field after clicking "submit", when I click the "Back" button to go from the summary page to the forms page, I should be able to request for that hidden field and apply my logic? At what point does the form/fields expire in terms of when I will not be able to used the posted data?
 
danieln4,
If i understand it correctly you'll have to make it store it as a session variable and check for that session variable. After that person closes the browser, the session variable is gone. I suppose you could also do it in cookies, but to me it seems easier to go for a session variable.
 
sorry meetings are killing me today.

anyhow, I wrote this sloppy/quick example for you to see the workings of what I mentioned.

follows as two pages one.asp and two.asp

one.asp
<html>
<head>
<script language=&quot;javascript&quot;>
function onSubmission() {
document.subForm.hidd.value = &quot;Submitted&quot;
}
</script>
</head>
<body>
<%
if request.querystring(&quot;hidd&quot;) <> &quot;Submitted&quot; then %>
<form name=&quot;subForm&quot; method=&quot;post&quot; action=&quot;two.asp&quot; onSubmit=&quot;onSubmission()&quot;>
<input type=&quot;text&quot; name=&quot;txt&quot;>
<input type=&quot;hidden&quot; name=&quot;hidd&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
</form>
<% else
response.write &quot;sorry you already filled the form out&quot;
end if
%>
</body>
</html>

two.asp
<html>
<head>
<script language=&quot;javascript&quot;>
function resubmitOnBackButton() {
return document.frm.submit();
}
</script>
</head>
<body onUnLoad=&quot;return resubmitOnBackButton()&quot;>
<%
response.write &quot;The form value submitted was &quot; & request.Form(&quot;txt&quot;)
%>
<form name=&quot;frm&quot; action=&quot;one.asp&quot;>
<input type=&quot;hidden&quot; name=&quot;hidd&quot; value=&quot;<%=request.form(&quot;hidd&quot;)%>&quot;>
</form>
now click the back button
</body>
</html>

this can be cleaned up quite a bit but I had to use NN to run it and I new this long winded way would work. hope that helps out a bit.

O' you can see it working here if you want


_________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
From what I read you want them to be able to go back and re-submit, you just don't want 2 records. If this is correct, onpnts suggestion wont work for you. I'd suggest storing a session variable and basing the sql string upon. If the session varaible is blank, then Insert * into dbo.blah.blah, if the session variable isn't blank then Update * Where * = some variable that you can use to track the user.

If session(&quot;formsubmitted&quot;) = &quot;&quot; then
strSQL = INSERT color, size INTO dbo.orders.shirts VALUES = 'red, medium'
ElseIf session(&quot;formsubmitted&quot;) <> &quot;&quot; then
strSQL = UPDATE color, size WHERE name = 'Fake Customer'
End If

I'm a bit too tired right now to remember how to set it so that the session(&quot;formsubmitted&quot;) is set when the user first enters there data but i'm sure someone else can chime in if this is the type of code you need.
 
Thanks guys. Both example does help with the ideas. I do want the user to be able to click the &quot;back&quot; button and viewed what they have inputted. However, I do not want to log the transaction again even if they made changes. Maybe I'll disable the submit button when they use the &quot;back&quot; button.

The only way that they can make any change after their first submission is to go back to the Intro page and then the forms page to make any updates. Keep in mind that I am only allowing one submission per transaction, unless the user start back at the intro page which will take him/her to the forms page.
 
danieln4

That is simple also.

if the condition is returned to be submitted already then you set the form fields to readonly. [wink]


_________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
never tried this but it sounds like it would work. try it!
<%
dim rOnly
if request.querystring(&quot;hidd&quot;) = &quot;Submitted&quot; then
rOnly = &quot;readonly&quot;
end if
%>
<form name=&quot;subForm&quot; method=&quot;post&quot; action=&quot;two.asp&quot; onSubmit=&quot;onSubmission()&quot;>
<input type=&quot;text&quot; name=&quot;txt&quot; <%=rOnly%>>
<input type=&quot;hidden&quot; name=&quot;hidd&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
</form>


in my mind it will output either
<input type=&quot;text&quot; name=&quot;txt&quot; >
or
<input type=&quot;text&quot; name=&quot;txt&quot; readonly>

hmmm... that jsut might work. [lol]

_________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
hey, I'm going to have to remember that. never thought of it and have gone through much longer ways to do it. [lol] anyhow I tried it and it does work fine. might want to keep it in mind also.

same link if you want to see it work

_________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
Nice, I wouldn't have even though of using the onUnsubmit event :)

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Onpnt,
I checked out your sample page and it function pretty good except for one small issue. On page one, I entered &quot;test3&quot; and clicked submit. The result took me to page two. I then click on the back button which brought me back to page one with the input field set either as disable or readonly. Without refreshing the page, clicked on submit again which brought me to page two with the default value &quot;test my box&quot; being submitted.

This goes back to my original problem where I did NOT want this event to be submitted twice whether the input field has been changed or not. I am only putting on this restriction whenever ever a user click the &quot;Back&quot; button. All other ways of getting to the page should allow the full submission.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top