Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: How to Redefine $search_box Output

Submitted by on July 23, 2010 – 8:47 amNo Comment

This article is devoted to changing of the standard search box which is passed to .tpl.php through $search_box variable.


Solution
Show a form in template

You need insert the following code:

<?php if ($search_box): ?><div class="block block-theme"><?php print $search_box ?></div><?php endif; ?>

Search form will be shown when:
  • Search standard module is activated
  • Search form showing is enabled (‘Search box’ is checked) on the page of theme settings (admin/build/themes/settings/< theme-name >)
  • Права доступа к форме поиска ("Поиск материалов") были установлены на странице "Контроль доступа" (admin/user/access) в зависимости от роли.
Change search form appearance
Step 1
  • Create template.php file if there is no such file in your theme.
  • Add the following code there:

<?php
function phptemplate_search_theme_form($form) {
/**
   * This snippet catches the default searchbox and looks for
   * search-theme-form.tpl.php file in the same folder
   * which has the new layout.
   */
return _phptemplate_callback(‘search_theme_form’, array(‘form’ => $form), array(‘search-theme-form’));
}
?>

Step 2

Snippet in template.php catches search form by default before its showing and finds search-theme-form.tpl.php in the same folder. This file defines new graphical design.

Very simple example of search-theme-form.tpl.php file (Druapl 4.x):

<label for="edit[search_theme_form_keys]">Search</label>
<input type="text" maxlength="128" name="edit[search_theme_form_keys]" id="edit-search_theme_form_keys" size="25" value="" title="Enter the terms you wish to search for." class="form-text" />
<input type="submit" name="op" value="Search" />
<input type="hidden" name="edit[form_id]" id="edit-search-theme-form" value="search_theme_form" />
<input type="hidden" name="edit[form_token]" id="a-unique-id" value="<?php print drupal_get_token(‘search_theme_form’); ?>" />

Snippet is updated and checked for compatibility with Drupal 4.7.x and Drupal 5.x:

<label for="search_theme_form_keys">Custom Search</label>
<input type="text" maxlength="128" name="search_theme_form_keys" id="edit-search_theme_form_keys" size="25" value="" title="Enter the terms you wish to search for." class="form-text" />
<input type="submit" name="op" value="Search" />
<input type="hidden" name="form_id" id="edit-search-theme-form" value="search_theme_form" />
<input type="hidden" name="form_token" id="a-unique-id" value="<?php print drupal_get_token(‘search_theme_form’); ?>" />

Attention:
You don’t need opening and closing tags in the search-theme-form.tpl.php. Drupal will when forms drawing.

Example. Changing text of "Search" button

Find the following line in search-theme-form.tpl.php:

<input type="submit" name="op" value="Search" />

and change it to:

<input type="submit" src="images/go-button.gif" name="op" value="GO!" />

Example. Replacing search button with a picture

You can do this using CSS. But if you wish to replace button with an image using your search-theme-form.tpl.php then you need to replace this code:

<input type="submit" name="op" value="Search" />

with this one:

<input type="image" src="images/go-button.gif" name="op" value="Search" />

Set correct path to the picture.

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.