0

I have a simple form. I am sending the form to same page that has the form. However, after every submit process, then when I want to refresh the page manually, the browser asks me:

Do you want to re-send the form?

How can I prevent this?

foo.php

<?php echo $_POST['id']; ?>

<form action="foo.php" method="post">
   <input type="text" name="id" value="">
   <input type="submit" value="Send">
</form>

Thanks!

Axel
  • 3,331
  • 11
  • 35
  • 58
Cris Denolatter
  • 223
  • 1
  • 2
  • 15

2 Answers2

0

check with a condition if the form was posted, process the form and then redirect using javascript.

<?php 
if (!empty($_POST["id"]( {

//do stuff
?>
<script>
location.href=("/");
</script>
<?
}
?>
Alex Angelico
  • 3,710
  • 8
  • 31
  • 49
0

Method 1: Check with a condition if the form was submited and then redirect to the same page.

if(isset($_POST['button_name_from_form'])) {
  #...code
  header('Location:page.php');
}

!! But make sure that header is before any output. !!

Method 2: Ajax