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

Posted on 2005-04-27
Last Modified: 2012-05-05
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!
Question by:Dcom4CIT
    LVL 46

    Assisted Solution

    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


    Author Comment

    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,
    LVL 52

    Accepted Solution

    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.

    Author Comment

    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!
    LVL 2

    Expert Comment

    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.
    LVL 52

    Expert Comment

    by:Carl Tawn
    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.
    LVL 46

    Expert Comment

    >>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

    LVL 52

    Expert Comment

    by:Carl Tawn
    Sorry Fritz, didn't read the post properly. Bit of a bad habit :o)
    LVL 46

    Expert Comment

    If I had a nickel every time I did that...


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    cleaning xml string 2 39
    Set cursor to client side 3 43
    ASP Syntax for IF statement 21 48
    Out the count variables 6 41
    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now