In Drupal we can customize everything, even the search forms. This example show you how to make a custom search block. First you have to make a file named "search-block-form.tpl.php" with this content:
<div class="container-inline">
<?php print $search_form; ?>
</div>
<?php print $search_form; ?>
</div>
even if it isn't different from the one in the core distribution; otherwise the preprocess function isn't executed.
After that you must to open the template.php and use the mechanism of preprocess function to modify template variables before they are passed into the template files.
function phptemplate_preprocess_search_block_form(&$vars, $hook) {
//modify title, size and button value of the search form
$vars['form']['search_block_form']['#title'] = t('New title');
$vars['form']['search_block_form']['#size'] = 24;
$vars['form']['submit']['#value'] = "New Value";
//Rebuild the rendered version
unset($vars['form']['search_block_form']['#printed']);
unset($vars['form']['submit']['#printed']);
$vars['search']['search_block_form'] = drupal_render($vars['form']['search_block_form']);
$vars['search']['submit'] = drupal_render($vars['form']['submit']);
//Group all variables
$vars['search_form'] = implode($vars['search']);
}
//modify title, size and button value of the search form
$vars['form']['search_block_form']['#title'] = t('New title');
$vars['form']['search_block_form']['#size'] = 24;
$vars['form']['submit']['#value'] = "New Value";
//Rebuild the rendered version
unset($vars['form']['search_block_form']['#printed']);
unset($vars['form']['submit']['#printed']);
$vars['search']['search_block_form'] = drupal_render($vars['form']['search_block_form']);
$vars['search']['submit'] = drupal_render($vars['form']['submit']);
//Group all variables
$vars['search_form'] = implode($vars['search']);
}
After that we can use the block section to add the block or use something like:
<?php
$block = module_invoke('search', 'block', 'view', 0);
print $block['content'];
?>
$block = module_invoke('search', 'block', 'view', 0);
print $block['content'];
?>
We can print all variables of the form to see the possibles values into the function (for testing use):
echo "<pre>";
print_r($vars['form']);
echo "</pre>";
print_r($vars['form']);
echo "</pre>";

Thank you !
Thanks you for this post. You are my hero.
Post new comment