我有HTML表单,当点击提交表单数据发送到同一个php
页面。但提交后我们刷新页面网页浏览器显示重新提交对话框。如何在页面刷新时停止表单提交
我的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 </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 :(得分:4)
非常简单,可能有很多解决方案,我使用的是在服务器端处理提交后只需将用户重定向到同一页面:
header("Location: site.com/your-form-page.php");
答案 1 :(得分:2)
重定向页面。
header('Location: http://www.example.com/');
答案 2 :(得分:2)
<?php
if(isset($_POST['submit']))
{
//Your code comes here
//Redirect at the end of process
header('Location: http://www.example.com/redirect.php');
}
?>