WEB how do you prevent form resubmitting?

Discussion in 'OT Technology' started by RiKuN, Aug 17, 2007.

  1. RiKuN

    RiKuN New Member

    Joined:
    Sep 20, 2006
    Messages:
    37
    Likes Received:
    0
    Like the title asks, how do you prevent form resubmitting? Say if you had a form that called on a function to increment a variable after it is submitted. What happens if the user refreshes the form or presses the back button? The form will be resubmitted and the variable is incremented again unintentionally. Is there anyway to prevent this?
    This is in PHP btw.
     
  2. massy

    massy New Member

    Joined:
    May 8, 2006
    Messages:
    24
    Likes Received:
    0
    I have such a script (http://www.thecoolwall.info) and I prevent double voting by submitting all the votes (in my case) in a table with primary keys on the ip and the car the vote is being cast on. If the user uses the back button, he/she can vote again but the vote doesn't go into the table. Problem solved :)
     
  3. Nakon

    Nakon Guest

    set a session variable when the form is submitted and check if it's set (if you're not using a database).

    Code:
    <?php
    
    //code goes here
    
    session_start();
    
    if (!$_SESSION['submitted'])
    {
        //code goes here
    }
    else
    {
        //error, submitted already
    }
    
     $_SESSION['submitted'] = true;
    
    ?>
    
     
  4. ge0

    ge0 New Member

    Joined:
    Oct 31, 2005
    Messages:
    8,398
    Likes Received:
    0
    Location:
    JERSEY
    or $_POST the variables to a new page then submit them into the table
     
  5. Mikey

    Mikey This one, this form I hold now, so Wide eyed and h

    Joined:
    Oct 18, 2001
    Messages:
    23,118
    Likes Received:
    0
    Location:
    Baltimore
    right, you would need to right all of the values to a table then do a compare when inserting new values.
     
  6. auveeb

    auveeb DATS CUTE

    Joined:
    Mar 22, 2005
    Messages:
    11,467
    Likes Received:
    0
    Location:
    New York City, NY
    Just disable the button onsubmit.
     

Share This Page