4 回答

TA貢獻1744條經驗 獲得超4個贊
將action您的表單指向example.com/contact,example.org/submitted以便將表單內容發布到您的submitted頁面。
然后,在你的submitted頁面上,檢查方法,并重定向到contacton GET(或者更好的是,所有不是的POST):
if ($_SERVER['REQUEST_METHOD'] !== 'POST')
header("Location: http://example.com/contact");
else if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST)) {
// validate input
// save to your CSV
// display `submitted` page
}

TA貢獻2011條經驗 獲得超2個贊
試試這個: contact.php
session_start();
...
$_SESSION['form-submitted'] = 0;
if(isset($_POST['submit'])){//use your button value
//do your stuff
$_SESSION['form-submitted'] = 1;
//redirect to submitted file
}
提交.php
if(isset($_SESSION['form-submitted']) && $_SESSION['form-submitted'] == 1){
//show content
} else {
//redirect to contact page
}
這將允許您捕獲獲取請求并檢查表單是否未提交。

TA貢獻1844條經驗 獲得超8個贊
你試過這個了嗎?
if (!isset($_POST)) {
header("Location: http://example.com/contact");
}

TA貢獻1793條經驗 獲得超6個贊
您可以通過這樣做來完成對 refferer 和請求方法的檢查:
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['HTTP_REFERER'] == "http://example.com/form") {
// Your code
}
- 4 回答
- 0 關注
- 161 瀏覽
添加回答
舉報