Jump to content

error catch form post


gish

Recommended Posts

hi everyone

 

I have setup up my web page so that after a form button is clicked 20 times the page automatically freshes itself. That works fine but that the creates and issue because I have pressed the submit button it posts the data then refreshed itself. but because it it refreshes anything that was posted it will ask if you want to post it again.

 

What I want to know is there anyway to error catch it so that I dodge it or clear the post variable.

 

gishaust

Link to comment
Share on other sites

Try This one..

<?php

function prevent_multi_submit($type = "post", $excl = "validator") {

    $string = "";

    foreach ($_POST as $key => $val) {

        // this test is new in version 1.01 to exclude a single variable

        if ($key != $excl) {

            $string .= $val;

        }

    }

    if (isset($_SESSION['last'])) {

        if ($_SESSION['last'] === md5($string)) {

            return false;

        } else {

            $_SESSION['last'] = md5($string);

            return true;

        }

    } else {

        $_SESSION['last'] = md5($string);

        return true;

    }

}

/* example of use:

if (isset($_POST)) {

    if ($_POST['field'] != "" && strlen < 25) { // place here the form validation and other controls

        if (prevent_multi_submit()) { // use the function before you call the database

            mysql_query("INSERT INTO tabel..."); // or send a mail like...

            mail($mailto, $sub, $body);

        } else {

            echo "The form is already processed";

        }

    } else {

        // your error about invalid fiels

    }

} */

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.