Advertisement
lalatino

preventing double form submit

Jun 11th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.80 KB | None | 0 0
  1. <?php
  2. ob_start();
  3. if (isset($_POST['send']) && $_POST['send']=='Send') {
  4.  /* save_form_data_to_database(); if(some_error) {echo 'There was an error!';} else */
  5.  { header('Location: '.$_SERVER['PHP_SELF'].'?status=ok'); exit; }
  6. }
  7. $str = ob_get_contents(); // get all printed text
  8. ob_end_clean();
  9. ?><!DOCTYPE html>
  10. <html>
  11. <head>
  12. <title>test for http://stackoverflow.com/questions/17028567/php-self-and-redirect-in-same-page</title>
  13. <style type="text/css">
  14. </style>
  15. <script type="text/javascript">
  16. </script>
  17. </head>
  18. <body>
  19.   <form name="myform" action="" method="post">
  20.     <input type="text" name="data1" value="aaa" />
  21.     <input type="submit" name="send" value="Send" />
  22.   </form>
  23. <?php
  24.  var_export($_POST);
  25.  var_export($_GET);
  26.  echo '<p> error message: '.$str.'</p>';
  27. ?>
  28. </body>
  29. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement