1

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
        }
?>
Elshan
  • 7,339
  • 4
  • 71
  • 106

3 Answers3

4

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");
slash197
  • 9,028
  • 6
  • 41
  • 70
2

redirect the page.

header('Location: http://www.example.com/');
YouSer
  • 393
  • 3
  • 12
2
<?php
if(isset($_POST['submit']))
{
//Your code comes here

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