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
https://forums.phpfreaks.com/topic/133853-error-catch-form-post/
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

    }

} */

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.