function om_search_alter in OM Tools 8
Same name and namespace in other branches
- 8.2 tools/search/search.inc \om_search_alter()
- 6 tools/search/search.inc \om_search_alter()
- 7.2 tools/search/search.inc \om_search_alter()
- 7 tools/search/search.inc \om_search_alter()
OM Tools Search Form Alters
File
- tools/
search/ search.inc, line 169 - Search form alters
Code
function om_search_alter(&$form, &$form_state, $form_id) {
// Make sure the js are added only once
static $search_form_js = 0;
static $search_block_js = 0;
switch ($form_id) {
case "search_form":
if (variable_get('om_tools_search_alter_switch', 0)) {
drupal_set_title(t(variable_get('om_tools_search_title', 'Search')));
$search_label = variable_get('om_tools_search_label', 1);
$search_label_text = variable_get('om_tools_search_label_text', 'Enter your keywords');
$search_size = variable_get('om_tools_search_size', 30);
$search_hover = variable_get('om_tools_search_hover', 'Enter the terms you wish to search for.');
$search_button = variable_get('om_tools_search_button', 'Go');
if ($search_label) {
unset($form['basic']['keys']['#title']);
$form['basic']['keys']['#default_value'] = $search_label_text;
$search_form_js++;
if ($search_form_js == 1) {
drupal_add_js("\n jQuery(document).ready(function(\$){\n \$('form#search-form input#edit-keys').val('" . $search_label_text . "');\n \$('form#search-form input#edit-keys').click(function() {\n if (\$(this).val() == '" . $search_label_text . "') { \n \$(this).val(''); \n };\n });\n \$('form#search-form input#edit-keys').blur( function() {\n if ((\$(this).val() == '" . $search_label_text . "') || (\$(this).val() == '')) {\n \$(this).val('" . $search_label_text . "');\n };\n }); \n }); \n ", "inline");
}
}
else {
$form['basic']['#title'] = $search_label_text;
}
$form['basic']['keys']['#size'] = $search_size;
$form['basic']['keys']['#attributes'] = array(
'title' => t($search_hover),
);
$form['basic']['submit']['#value'] = t($search_button);
break;
}
case "search_block_form":
if (variable_get('om_tools_search_block_alter_switch', 0)) {
$search_block_label = variable_get('om_tools_search_block_label', 1);
$search_block_label_text = variable_get('om_tools_search_block_label_text', 'Search this site');
$search_block_size = variable_get('om_tools_search_block_size', 15);
$search_block_hover = variable_get('om_tools_search_block_hover', 'Enter the terms you wish to search for.');
$search_block_button = variable_get('om_tools_search_block_button', 'Go');
if ($search_block_label) {
unset($form['search_block_form']['#title']);
$form['search_block_form']['#default_value'] = $search_block_label_text;
$search_block_js++;
if ($search_block_js == 1) {
drupal_add_js("\n jQuery(document).ready(function(\$){\n \$('form#search-block-form input.form-text').val('" . $search_block_label_text . "');\n \$('form#search-block-form input.form-text').click(function() {\n if (\$(this).val() == '" . $search_block_label_text . "') { \n \$(this).val(''); \n };\n });\n \$('form#search-block-form input.form-text').blur( function() {\n if ((\$(this).val() == '" . $search_block_label_text . "') || (\$(this).val() == '')) {\n \$(this).val('" . $search_block_label_text . "');\n };\n }); \n }); \n ", "inline");
}
}
else {
$form['search_block_form']['#title'] = $search_block_label_text;
}
$form['search_block_form']['#size'] = $search_block_size;
$form['search_block_form']['#attributes'] = array(
'title' => t($search_block_hover),
);
$form['actions']['submit']['#value'] = t($search_block_button);
break;
}
}
}