我有一个带有登陆页面的网站,在页面底部有一个表格。我想要做的就是显示一条验证消息并将用户再次重定向到表单,这样他就可以在不滚动的情况下查看消息。代码如下(同页): //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 关注
- 112 浏览
添加回答
举报
0/150
提交
取消