提交时未处理PHP表单

提交时未处理PHP表单,php,html,forms,Php,Html,Forms,在原始查询中没有显示任何结果之后,我有一个通过php显示的表单。表单显示良好,但提交后将转到index.php,而不是使用$\u服务器['php\u SELF']进行处理 echo "<form method='post' action='". $_SERVER['PHP_SELF']."'>"; echo $error['find']; echo "<p><label for='find'>Search for Your Favorite Location:

在原始查询中没有显示任何结果之后,我有一个通过php显示的表单。表单显示良好,但提交后将转到index.php,而不是使用
$\u服务器['php\u SELF']
进行处理

echo "<form method='post' action='". $_SERVER['PHP_SELF']."'>";
echo $error['find'];
echo "<p><label for='find'>Search for Your Favorite Location:</label><br />";
echo "<input type='text' id='find' name='find' value='".($_POST['find'] ? htmlentities($_POST['find']) : '')."' /></p>";
echo "<p><input type='submit' name='submitLocation' value='Submit' /></p></form>";
echo”“;
echo$error['find'];
echo“搜索您最喜欢的位置:
”; 回声“

”; 回声“

”;
您可以通过将
操作保持为空来实现该结果。我稍微整理了一下代码,现在看起来是这样的:

<?php
if (isset($_POST['submitLocation'])) 
{
 echo isset($_POST['find']) ? htmlentities($_POST['find']) : '';
}
?>

<html>
<body>
<form action="" method="post">
<p><label for='find'>Search for Your Favorite Location:</label><br/>
<input type='text' id='find' name='find' value='' /></p>
<input type='submit' name='submitLocation' value='Submit' />
</form>
</body>
</html>

搜索您喜爱的位置:


它检查表单是否使用PHP函数提交。如果是:那么它只是回显用户输入的字符串

只需将
action
留空即可。(但请注意:如果此表单是在index.php上的include语句中生成的,您将调用“index.php”)
$\u服务器['php\u SELF']
不是表单的本地文件,而是表单打开时的URL,因此如果它在
http://www.mysite.com/index.php
它将引导你回到那里,就像上面提到的狗鼻子一样。谢谢你的及时回复。表单不在index.php上,而是在wordpress的“页面”上。我将试着把action留白,看看结果如何。几年前我就听说使用PHP_SELF是一种安全缺陷。你应该避免。