2014-03-28 37 views
1

后,我有HTML表单,当点击提交后,提交表单数据发送到同一php page.But我们刷新页面网页浏览器显示重新提交dialog.How它的停止形态在页面刷新时提交。提交HTML表单如何停止形式resubmision当页面刷新

enter image description here

我的HTML代码: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代码(同一页):的index.php

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

我觉得同样的问题:http://stackoverflow.com/questions/19346762/how-to-prevent-page-redirection-refresh-after-form-submit-while-preserving-file – Eddie

+0

我的表单操作本身。 – Elshan

+1

使用PHP头位置 –

回答

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

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

重定向的页面。

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

很简单,有可能是多种解决方案,我用的是处理在服务器端提交后只是简单地将用户重定向到同一页:

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

你也可以以显示消息发送一个查询字符串(GET)参数与沿重定向页面相同的位置。 –