Thread: Mutiple Submits

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    29
    Rep Power
    0
    What is the best way to stop people from pressing the submit button more than once and having mutiple insertions. Basically when a user clicks submit 3 or 4 times i get 3 or 4 signatures in my guestbook

    Cisk
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    SPAIN
    Posts
    47
    Rep Power
    15
    You can try the following:

    in the form tag, add:

    <form .... onSubmit="checkifsend()">

    and create a Javascript function like:

    function checkifsend()
    {
    if (Hasbeensend)
    {return false}
    else {Hasbeensend=true; return true}
    }

    Note:Hasbeensend has to be defined as false when loading the page, inside the <script> section.

    Explanation: When the form is send, the script checks if it has been sended before. If it's the first time, it changes the value of Hasbeensend to true and submits it, avoiding other submits.

  4. #3
  5. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    61
    I really don't understand how it's possible to submit more than once, unless the form ACTION is to submit to itself (rather than forward the values to another page).

    Basically, once you hit submit, the page to which the ACTION goes starts loading immediately, so it's impossible to click the same button twice. I've even tried using the middle button of my mouse (which is configured as a double-click) to submit a form and I only get one action.

    I would guess that there are two possibilities:
    1. the form ACTION is handled inside the same file in which the user fills out the form, thus presenting the button for a second click
    2. the user is not clicking the button twice, but is refreshing the page after submitting, which submits the page again. That would require some other code, perhaps using a cookie.

    If I'm wrong, please explain, because I have never been able to reproduce the "double-click submit" phenomenon.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    29
    Rep Power
    0
    Argrajoca:
    Thanks a lot! That works great

    rycamor:
    Well youre right. The form calls the same page. I've trie drefreshing the page, after submission, and it has never re-submitted information using both GET and POST. I have another contact form on my webpage that spans 2 .php pages and i'm going to test out submitting more than once on that one.
    http://www.txraves.org/djcisk/signbook.php - is the page that i have the form in. I also used the .disable javascript functiont to disable the button

    Cisk

Similar Threads

  1. cookie used to prevent mutiple form submissions
    By davidgraham16 in forum PHP Development
    Replies: 2
    Last Post: December 18th, 2003, 01:22 PM
  2. My form still submits when it should not
    By dslavens in forum HTML Programming
    Replies: 5
    Last Post: October 22nd, 2003, 02:22 PM
  3. explode what the user submits
    By metro in forum PHP Development
    Replies: 1
    Last Post: April 25th, 2003, 02:55 PM
  4. multiple form submits and pop up windows
    By bakedbean in forum HTML Programming
    Replies: 1
    Last Post: March 9th, 2003, 02:16 PM
  5. document.form.submit() fails after too many submits
    By hobbis in forum HTML Programming
    Replies: 0
    Last Post: November 29th, 2001, 05:20 AM

IMN logo majestic logo threadwatch logo seochat tools logo