如何制作没有搜索按钮的搜索表单?

How to make the search form without the search button?

此问题与 CSS/HTML 和 drupal 网络开发有关。我正在使用 Drupal 7 开发网站。默认情况下,Drupal 提供 Search form(如图所示),旁边有输入文本框和按钮。我怎样才能删除该搜索按钮并使其像文本输入框一样,例如您可以看到 Whosebugsearch form。因此,无需单击按钮,只需输入文本并输入即可。谢谢

注意:Drupal 是内容管理系统。为什么我在这里问这个问题,因为解决方案与 CSS/HTML 有关。

您可以通过在主题中实施 YOURTHEME_form_search_block_form_alter 来更改搜索表单。通过将 #access 放在 false 上,您将禁用表单上按钮的呈现。

function YOURTHEME_form_search_block_form_alter(&$form, &$form_state, $form_id) {
    $form['actions']['submit']['#access'] = false;
}

如果您想隐藏提交按钮但保留自动提交输入的可能性,您可以使用 css:

隐藏提交按钮
#edit-custom-search-blocks { //replace this selector with ID of your submit button
      position: absolute;
      top: -999px;
      left: -999px;
      width: 0px;
      height: 0px;
}

您可以将它放在默认的 CSS 文件中。 (然后清除 Drupal 缓存)