Skip to content Skip to sidebar Skip to footer

Why A Form Would Automatically Resubmitted When The Page Is Refreshed

Does anyone know why a form would automatically resubmitted when the page is refreshed? I an setting a javascript cookie to test whether or not to refresh the page - if it's 'YES'

Solution 1:

A common approach to address this issue is to monkey with the POST recipient:

After the catching script has done all of the processing required by the POST, throw a Location: header that redirects to the the currently requested URI. This has the affect of the browser recognizing the final destination as not having received a POST, and therefore refreshing won't resubmit the POST.

PHP Example

page.php

<?phpif (!empty($_POST)) {
    // Do some stuff
    header('Location: page.php');
    // The second time around _POST won't have any data,// so there's not worry of an infinite loopexit;
}
?><h1>Hi, I will never try to resubmit POST data!</h1>

Solution 2:

FireFox is designed to save your forms/inputs, which includes submit buttons. This is really helpful when developing sites with forms so you don't have to keep filling them out, but it can get in the way sometimes, but it's a browser feature, not a code issue.

Solution 3:

If you POSTed to get to the current page (instead of a post then a response.redirect to GET the current page), when you hit the browser's refresh button, it's going to re-POST. I'm not sure how that relates to your hidden Iframe issue, though. (It seems I'm duplicating what Shad just said, in essence).

Post a Comment for "Why A Form Would Automatically Resubmitted When The Page Is Refreshed"