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: Disappearing Text In Search Form

Submitted by on September 6, 2010 – 8:52 amNo Comment

Problem:

You need to show “Search” text to the respective field in search form. When user clicks on this field, the text should disappear.

Solution:

Disappearing hint in search field using JavaScript

Add (or change) the following function in template.php file of fa current theme:

function phptemplate_preprocess_search_theme_form(&$vars, $hook) {
$form_default = t(‘Search’);
$vars[‘form’][‘search_theme_form’][‘#value’] = $form_default;
$vars[‘form’][‘search_theme_form’][‘#attributes’] = array(
‘onblur’ => “if (this.value == ”) {this.value = ‘{$form_default}';}”,
‘onfocus’ => “if (this.value == ‘{$form_default}’) {this.value = ”;}”
);
}

Using jQuery for hiding the hint in search field

  • In the settings of a current theme, enable showing of a search string – see admin/build/themes/settings
  • Add (or change) the following function in template.php file of a current theme:

    function phptemplate_preprocess_search_theme_form(&$vars, $hook) {
    $theme_path = drupal_get_path(‘theme’, ‘arthemia’);
    $vars[‘form’][‘search_theme_form’][‘#value’] = t(‘Search’);
    drupal_add_js($theme_path. ‘/search_box.js’);
    }

  • Create search_box.js file in a folder of a current theme with the following code:

    var active_color = ‘#000′; // Colour of user provided text
    var inactive_color = ‘#ссс'; // Colour of default text
    $(document).ready(function() {
    $(“input.form-text”).css(“color”, inactive_color);
    var default_values = new Array();
    $(“input.form-text”).focus(function() {
    if (!default_values[this.id]) {
    default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
    this.value = ”;
    this.style.color = active_color;
    }
    $(this).blur(function() {
    if (this.value == ”) {
    this.style.color = inactive_color;
    this.value = default_values[this.id];
    }
    });
    });
    });

Useful links:

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.