我有一個帶有登陸頁面的網站,在頁面底部有一個表格。我想要做的就是顯示一條驗證消息并將用戶再次重定向到表單,這樣他就可以在不滾動的情況下查看消息。代碼如下(同頁): //validation if (isset($_POST['submit'])) { $name = htmlspecialchars(stripslashes(trim($_POST['name']))); if (!preg_match("/^[A-Za-zà-??-??-?]/", $name)) { $name_error = 'invalid name'; } //i want to redirect as soon as the validation finishes header('Location: http://localhost/myweb/index.php#contact'); } <form id="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST"> <input type="text" name="name" id="name"> <button type="submit" id="submit" name="submit">Send</button></form>我嘗試了以下所有方法:window.location.href = 'index.php#contact';在按鈕 ( onclick) 和表單 ( onsubmit)中使用header在代碼的多個部分中使用,也與exit();但是,這里是關鍵,我不想只使用另一個 php 頁面進行驗證(因為我需要使用session_start()并且我想避免使用 cookie)而且我不想使用 AJAX XMLHttp 請求。有可能做到嗎?
1 回答

縹緲止盈
TA貢獻2041條經驗 獲得超4個贊
我在這樣的表單操作中使用#contact
<form id="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>#contact" method="POST">
你試過這個嗎?
- 1 回答
- 0 關注
- 121 瀏覽
添加回答
舉報
0/150
提交
取消