搜索表单的空值


Empty value of a search form

我想从我正在开发的页面中搜索地址簿。通讯簿是另一个页面的内容,此页面上通讯簿的 URL http://example.com/start.php。此地址簿有自己的搜索字段,我将用于我的页面。我写了以下搜索表单:

<form action="http://example.com/start.php" method="post" target="_blank">
<div>
<input type="hidden" value="adress" name="cmd" /> 
<input id = "adressinput" name="search" type="text" title="Search in the adress book [ctrl-f]" accesskey="f" value="adress book" />
<input id="refresh" title="refreshnow" name="refresh" type="image" src="icons/Downloads/arrow-circle-single.png" class="iconbutton"/>                               
</div>
</form>

问题是,当我在表单的文本框中写一些东西,然后单击图标 refreshnow,会显示页面 http://example.com/start.php(地址簿),但此页面的搜索字段仍然具有空值,当然,我没有得到任何结果。

这不是我的第一个搜索表单。我写过类似的表格,它们有效,所以,我不知道为什么它不起作用。

  1. 从表单中删除目标属性,地球上绝对没有理由再使用弹出窗口。

2.) 您使用什么脚本语言?如果你是PHP引用了$_POST['search']还是你不小心引用了$_GET['search']

此行

<input id = "adressinput" name="search" type="text" title="Search in the adress book [ctrl-f]" accesskey="f" value="adress book" />

应该是

<input id="adressinput" name="search" type="text" title="Search in the address book [ctrl-f]" accesskey="f" value="<?php echo $_POST['search']; ?>" />

或者你可以做一些更聪明的事情

if (isset($_POST['search'])) {
    ?>
    <input id="adressinput" name="search" type="text" title="Search in the address book [ctrl-f]" accesskey="f" value="<?php echo $_POST['search']; ?>" />
    <?php
} else {
    ?>
    <input id="adressinput" name="search" type="text" title="Search in the address book [ctrl-f]" accesskey="f" value="adress book" />
    <?php
}  

这有点混乱,您也可以在inputvalue中使用变量,以便文件中的行数会更少,例如

if (isset($_POST['search'])) {
    $value = $_POST['search'];
} else {
    $value = 'adress book'
}
<input id="adressinput" name="search" type="text" title="Search in the address book [ctrl-f]" accesskey="f" value="<?php echo $value; ?>" />

其中$_POST['search']将包含输入的搜索词的值(一旦提交表单。

这是查询数据库以查找与其内容匹配的搜索结果所需的值。