Stopping users from been able to click multiple submits with the same form input!

Hi all,
I'm working with ASP (obviously) with an access database!
I have this page that allows the user to apply online for a course.
The action in the form tag calls a page that checks all required filelds were filled & only adds the users details if they were (or else an error page is displayed saying "Required field(s) name, address, etc.... weren't filled!")

Regular enough senario!

But my problem is that the user can use their back button to go back to the application page & hit submit again!
Then there is another record created for them in the database.

I could use code like the following at the top of my application page:

' ### Make the page reload on using the back button! ### < START >
' This makes sure that the page is reloaded when the user uses the back button!
' Got from:
'no cache - BROWSER
  Response.Expires = 0
  Response.Expiresabsolute = Now-1
  Response.AddHeader "pragma","no-cache"
  Response.AddHeader "cache-control","dim"
' no cache - PROXY
  Response.CacheControl = "no-cache"
  response.buffer = true
' ### Make the page reload on using the back button! ### < END >

This would force a refresh (well in Internet Explorer anyway).
But in the event of the user not filling in all the required fields & a descriptve error message(s) been displayed to them, I would like the back button to be allowed because this then would prevent them from having to re-fill out the whole application again!
Also I don't want to disable the submit button on the application page or anything like that, because after one user has applied they might also want to apply for their friends!

I assume I have a few options:
1. Put in the code above to force a refresh & therefore the user HAS to re-fill the entire application each time!
2. Allow the back-button but have a check for a duplicate record in the database before I add in the new application.
3. Use the code above to force a refresh but store the previously selected & typed values in ASP variables, maybe sessions. And re-populate these when the application page is displayed!

Also while I'm on the subject of refreshing etc..
Does anyone have code that will force a refresh on both FireFox & Intrernet Explorer!

Can someone please tell me which option is best, or point me in the right direction!
Much much thanks!
Who is Participating?
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
You could just set a session variable indicating that the form has been submitted, and then clear it again at the start of your second page.

Something like:

            If Session("PageSubmitted") = False Then

                Session("PageSubmitted") = True

                '// Do your validation stuff here
                If PageIsValid() Then
                    Response.Redirect "SomePage.asp")
                    '// Page was invalid, so clear flag to allow resubmit
                    Session("PageSubmitted") = False
                End If

            End If

Hope this helps.
fritz_the_blankConnect With a Mentor Commented:
What I do, and it is a pain in the butt is as follows:

1) I create a sql select with all of the values entered in the form
2) I execute that sql select against the database
3) If I am at EOF, that means that the values are unique, so I add the record
4) Otherwise, I give an error saying that the record has been added already

In regards to 3 and 4)

strSQL = "SELECT * FROM tblYourTable WHERE fldSomeField = '" & Request.Form("fldSomeField") & "' AND fldSomeOtherField = '" & & Request.Form("fldSomeOtherField ") & "';"
objRS.Open strSQL, objConnection,3,3
if objRS.eof then
     objRS("fldSomeField") =  Request.Form("fldSomeField")
     objRS("fldSomeOtherField") =  Request.Form("fldSomeOtherField")
  response.write("Record has already been added...")
end if
set objRS = Nothing

Dcom4CITAuthor Commented:
Maybe I don't have to use the force refresh code if:

4. On the successful application form been filled & successfully added to the database I should redirect to the application form page.
That would show the application page with it's blank/default values.
Also I could have a session variable within the application page which is called with a responce.wrie, this session variable would tell the user "Congrads on a successful application!"
Obviously it would be blank/null if the user hasn't been successful & any other page would then blank/null the session variable.

This idea is good but I'd still like the "Congrads" page to be seperate, this solution also somewhat places teh user into an expecation of filling in more application forms.

Any ideas,
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Dcom4CITAuthor Commented:
Thanks fritz_the_blank & carl_tawn,
I'll test those answers tomorrow (2.30am Ireland here). But carl I don't see how your answer would stop the back-button to re-submit & hence re-insert a second, identical record.
Maybe I'm missing something!
I'll look again in the morn.
Thanks a mil!
I use javascript to do it.

This is the submit button:
<input type="button" onclick="submitForm();" value="Submit">
This is the hidden var that keeps the user from submitting again.
<input type="hidden" name="processed" value="1">

This is the submitForm() function

function submitForm(){

I just wrote that on the fly so it may have syntax errors, it's just a concept, I use it all the time.
I use a simmilar function to see that the whole page is loaded so the user dosen't submit a partal form:

function save(){
alert('Wait for the page to load turbo!')

You would stick a <input name="ready" value="1" at the bottom of your page (inside the form of course)


P.S. Fritz the Blank has more brains in his pinky toe than I do in my whole body.
Carl TawnSystems and Integration DeveloperCommented:
The other option of course would be to do a select on the table prior to doing the insert. Essentially checking if the record exists before you try to add it.
>>P.S. Fritz the Blank has more brains in his pinky toe than I do in my whole body.<<

Somehow I doubt that!!!!

>>The other option of course would be to do a select on the table prior to doing the insert. Essentially checking if the record exists before you try to add it.<<

That is what I think. See my first post to this thread: http:#13880751 

Carl TawnSystems and Integration DeveloperCommented:
Sorry Fritz, didn't read the post properly. Bit of a bad habit :o)
If I had a nickel every time I did that...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.