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!

Destroy form data

Status
Not open for further replies.

Stoemp

Programmer
Sep 25, 2002
389
BE
Hi,

is it possible to destroy form data after the data is being stored? I make myself clear here:

Situation: User inputs data with a form. I store the data in a db with asp. User gets message 'succesfully stored data'. When the user hits 'refresh', the form data is being sent again. I want to avoid this.

I have one solution: redirect the user to another page or section on the page. The problem is I have so many forms that the code is beginning to become very huge.
I'm searching a way to discard all form data after the data is being stored so that the user can refresh as much as he wants.

Thanks,
Steven
 
It's a simple ideea:

On the submit page just add there
<%
Session(&quot;added&quot;)=false
%>

And then in the action asp
<%
If Session(&quot;added&quot;) then
'already added 1
Response.redirect &quot;submitdatapage.asp&quot;
Response.End
end if
Session(&quot;added&quot;)=true
'add the record
%>

________
George, M
 
Good idea, but this does not help me avoiding the message you get when you refresh the page. IE asks then if you would like to re-submit the form data.

Thanks anyway
 
You cant avoid that if you dont Redirect the user.

Response.Expires=-1
and
Response.Redirect Request.ServerVariables(&quot;HTTP_REFERER&quot;)

________
George, M
 
to work around IE's behaviour of wanting to warn/prompt the user that they are resubmitting form data, send them to another page just after you process the form that does not do any processing of its own, e.g.
page 1 is form that posts to page 2
page 2 processes form, but then sends user to page 3
page 3 can now be reloaded without crying about resubmitting form data.

to expand on shaddow's concept of &quot;expiring&quot; the data via a session variable, which is a very good idea as well (imagine that your users still can hit their back button and re-post a form all over again!) is to use a uniquely generated &quot;key&quot; that you can store in a session var, and include that in the form. as the form is submitted, compare the key in the session var to the key submitted with the form. if they match, process the form and then update (randomize again) the key in the session var. If the same form is posted again, the keys won't match and you can ignore the form.

best regards,
-f!
 
Thx Funka. I did this and it works just fine. It's a very simple but effective solution. Earlier I set the properties so that the pages do not cache. The problem of users re-submitting over and over again is not an issue here.

Thx,
Steven
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top