搜索字段和按钮

时间:2017-12-05 18:16:32

标签: php html css

我有一个搜索栏和旁边的按钮。它完全正常,一切都很好。但是在手机上输入内容并点击手机键盘时,搜索"它转到404错误。但是当我输入某些内容并点击"搜索按钮"有用。我只想点击"搜索"在电话键盘上没有它去404。

这是我的搜索字段和按钮:

<div id="search" class="search" style="margin-left: 20px;">
<input class="form-control" type="text" placeholder="Hvad leder du efter?.." name="search" value="<?php if(isset($search)) echo $search; ?>" />
<button type="submit" class="button-search"></button>

我只是不明白为什么&#34;搜索按钮&#34;工作,而不是&#34;搜索&#34;在手机键盘上

2 个答案:

答案 0 :(得分:0)

在表单中插入一个额外的隐藏提交。

<input type="submit" style="display: none"/>

答案 1 :(得分:0)

希望这可能会有所帮助 添加form代码,其中包含定位当前网址或搜索页面的操作属性     

function get_current_url()
{
        $ssl = false;
        $hostname = 'example.org';
        return ($ssl ? 'https' : 'http') . '://' . $hostname . $_SERVER['REQUEST_URI'];


}

$q = isset($_GET['q']) ? $_GET['q'] : false;
if($q !== false) {
     echo 'searching for :' . htmlspecialchars($q); 
}

?>

<div id="search" class="search" style="margin-left: 20px;">
<form method='GET' action='<?= $get_current_url; ?>' >
<input class="form-control" type="text" placeholder="Search.." name="q" value="<?php if(isset($_GET['q'])) echo htmlspecialchars($_GET['q']); ?>" />
<input type="submit" value='Search' class="button-search"></button>
</form>
</div>
相关问题