删除地址栏中的“名称”按钮


Removing the Name button in the address bar

当我尝试在表单中搜索我在地址栏中看到以下条目

check.php?go_btn=&s=香蕉

为什么我得到按钮的名称"go_btn"我应该得到的值

check.php?s=香蕉

为什么这个值

name="go_btn"

出现在地址栏中

simple_search.html

<form action="check.php" method="get" id="my_form"> 
<input name="go_btn" type="submit" id="go_btn" form="my_form" formaction="check.php" 
formmethod="get"
style="background-image: url(images/go.png); border: solid 0px #000000; width: 
71px; height: 55px;" value="">
<input type="text" name="s" id="s">
</form>

check.php

<?php
if (isset($_GET['go_btn'])) {
$s_find = $_GET['s'];
if ($s_find == "banana") {
print ("you find banana");
 }
else {
print ("blablabla....");
   }
}
?>

你得到它是因为你要求它:

<input name="go_btn" [..snip...] value="" />
        ^^^^^^^^^^^

任何具有name属性的<input>字段都将与表单的其余部分一起提交。如果不希望提交go_btn,则取消name属性。

好吧,在你的PHP中,不要询问go_btn,而是询问s,如下所示:

<?php
if (isset($_GET['s'])) {
   $s_find = $_GET['s'];
   if ($s_find == "banana") {
      print ("you find banana");
   }
   else{
      print ("blablabla....");
   }
}
?>

然后从表单的元素go_btn中删除属性名称,如下所示:

<form action="check.php" method="get" id="my_form"> 
<input type="submit" id="go_btn" form="my_form" formaction="check.php" 
...

你会得到它,因为你要求它。你的表单方法是GETGET方法接受URL中的所有值。如果您不想在URL中看到这些值,可以使用POST方法。

此外,URL中的该术语不应该有任何问题,因为您在其他文件中需要该变量。