Elshan
Elshan

Reputation: 7683

After Submitting HTML form how to stop form resubmision when page refresh

I have HTML form and when click submit form data send to same php page.But after submitting we refresh the page web browser show re-submission dialog.How it's stop form submitting while page refreshing.

enter image description here

My HTML Code: index.php

<form id="cfrm" method="post" action=".">
    <label>If you don't like this colors you can suggest it from here by selecting or copy and paste &nbsp;</label><input class="color" type="text" name="color1" placeholder="Color 1:ex #AAA" required=""/>
    <input class="color" type="text" name="color2" placeholder="Color 1:ex #CFC" required=""/>
    <input type="submit" id="click" value="Set Colors" name="btnSubmit" />
</form>

PHP code(same page) : index.php

<?php
        if (isset($_POST["btnSubmit"])) {
            $c1 = isset($_POST['color1']) ? $_POST['color1'] : '';
            $c2 = isset($_POST['color2']) ? $_POST['color2'] : '';
            //and do some task here
        }
?>

Upvotes: 1

Views: 3318

Answers (3)

Dinesh Babu
Dinesh Babu

Reputation: 456

<?php
if(isset($_POST['submit']))
{
//Your code comes here

//Redirect at the end of process
header('Location: http://www.example.com/redirect.php');
}
?>

Upvotes: 2

slash197
slash197

Reputation: 9034

Pretty simple, there are probably numerous solutions, what I use is after processing the submission on the server side just simply redirect the user to the same page:

header("Location: site.com/your-form-page.php");

Upvotes: 4

YouSer
YouSer

Reputation: 393

redirect the page.

header('Location: http://www.example.com/');

Upvotes: 2

Related Questions