清除表单并重定向回索引

Clear form and redirect back to index

本文关键字:索引 重定向 表单 清除      更新时间:2023-09-26

我有一个表单,它接受输入并将其输入到数据库中。这很好,运行得很好,只是我在清除表单时遇到了问题。在Wamp中,我只需要联系form.php,这是一个空白页。我一直在试图找到一种将用户重定向回index.php并清除表单的方法。通过四处搜索,我尝试了一些事情(可能是错误的(,包括将其放在我的php末尾:

header('Location: http://stackoverflow.com');

我还试着写一个JS函数来实现

<p><input type="submit" name="submit" value="Submit" onclick="clearForm();"></p>

js

function clearForm(){
    alert("Thanks, we will be in touch shortly");
    document.getElementById("contactForm").reset();
}
function clearForm(){
      alert("Thanks, we will be in touch shortly");
      window.location=ur_url_here;
}

当您获得重定向表单时,将自动重置

function clearForm(){
      alert("Thanks, we will be in touch shortly");
      window.location='http://stackoverflow.com';
}

没有必要专门清除表单,除非您使用其他元素来保存详细信息,否则当您移动到新页面时,表单将被忘记。

function clearForm() {
    alert("Thanks, we will be in touch shortly");
    window.location='http://stackoverflow.com';
}