Hi,

I've set up my own sub theme of zen classic. In my page.tpl.php file I have

<?php print $search_box; ?>

But how do I change the html of this ... for example I want to change the value of the input to 'search this site', as well as adding a couple of divs so I can add some custom syling.

I've searched for this but don;t seem to be able to find any instructions, does anyone know any links or could tell me how to do it?

Thanks!

Comments

unxposed’s picture

A link anyone?

unxposed’s picture

Okay so if I change '#default_value' => '' To what I want in the core search.module then this appears on my site - obviously I don't want to change the core. So how would I go about changing this in templates.php in my theme?... Would I need to add any new .tpl.php files? And how would I go further to add new div's around the search box - I can;t see any reference to the divs that are created in the core files?

function search_box(&$form_state, $form_id) {
  $form[$form_id] = array(
    '#title' => t('Search this site'),
    '#type' => 'textfield',
    '#size' => 15,
    '#default_value' => '',
    '#attributes' => array('title' => t('Enter the terms you wish to search for.')),
);

  $form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
  $form['#submit'][] = 'search_box_form_submit';
  $form['#validate'][] = 'search_box_form_validate';

  return $form;
}
ktleow’s picture

Just simply copy the file search-theme-form.tpl.php from modules/search directory to your theme folder.
Open the file, there are instructions and explanations inside on how to override the search form.

-----
http://kahthong.com - A blog, portfolio & personal site
My blog is proudly powered by Drupal

unxposed’s picture

Great thanks!

I've copied the search-theme-form.tpl.php into my sub theme directory and changed the code to

<div id="search" class="container-inline">
<div class="search_top"><!--search top--></div>
<div class="search_content"><?php echo $search['search_theme_form'] . $search['hidden'] . $search['submit']; ?><!-- search content --></div>
<div class="search_bottom"><!--search bottom--></div>
<!-- container inline--></div>

This is great as I can add new div's to the search box. but does't address tweaking the finer detail. i.e. I have the variable $search['search_theme_form'] which prints a div with class of form-item, a label, and an input box of:

<input type="text" maxlength="128" name="search_theme_form" id="edit-search-theme-form-1" size="15" value="" title="Enter the terms you wish to search for." class="form-text" />

What if I want to change value="" to value="Search this site"? How would I go about changing this. Or if I wanted to remove the div with class of form-item, which to me seems a bit reundent, and possibly add some paragraph tags in its place?

From what I've read I need to paste a funtion from search.module in my theme template.php, changing a few details, but I just can't find which bit I need to copy, or what needs changing... Any help would be really appreciated. Here are a few things that may be relevent in search.module:

/**
 * Process variables for search-theme-form.tpl.php.
 *
 * The $variables array contains the following arguments:
 * - $form
 *
 * @see search-theme-form.tpl.php
 */
function template_preprocess_search_theme_form(&$variables) {
  $variables['search'] = array();
  $hidden = array();
  // Provide variables named after form keys so themers can print each element independently.
  foreach (element_children($variables['form']) as $key) {
    $type = $variables['form'][$key]['#type'];
    if ($type == 'hidden' || $type == 'token') {
      $hidden[] = drupal_render($variables['form'][$key]);
    }
    else {
      $variables['search'][$key] = drupal_render($variables['form'][$key]);
    }
  }
  // Hidden form elements have no value to themers. No need for separation.
  $variables['search']['hidden'] = implode($hidden);
  // Collect all form elements to make it easier to print the whole form.
  $variables['search_form'] = implode($variables['search']);
}
/**
 * Form builder; Output a search form for the search block and the theme's search box.
 *
 * @ingroup forms
 * @see search_box_form_submit()
 * @see theme_search_box_form()
 */
function search_box(&$form_state, $form_id) {
  $form[$form_id] = array(
    '#title' => t('Search this site'),
    '#type' => 'textfield',
    '#size' => 15,
    '#default_value' => '',
    '#attributes' => array('title' => t('Enter the terms you wish to search for.')),
  );
  $form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
  $form['#submit'][] = 'search_box_form_submit';
  $form['#validate'][] = 'search_box_form_validate';

  return $form;
}
/**
 * Implementation of hook_theme()
 */
function search_theme() {
  return array(
    'search_theme_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'search-theme-form',
    ),
    'search_block_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'search-block-form',
    ),
    'search_result' => array(
      'arguments' => array('result' => NULL, 'type' => NULL),
      'file' => 'search.pages.inc',
      'template' => 'search-result',
    ),
    'search_results' => array(
      'arguments' => array('results' => NULL, 'type' => NULL),
      'file' => 'search.pages.inc',
      'template' => 'search-results',
    ),
  );
}

Thanks in advance!

ktleow’s picture

No you don't have to go into those details and functions.

Please refer to how I did for my Agregado theme:

<div id="search" class="container-inline">
  <?php $search['search_theme_form'] = '<div class="form-item" id="edit-search-theme-form-wrapper"><input type="text" maxlength="128" name="search_theme_form" id="edit-search-theme-form-1" size="15" value="Enter a keyword." title="Enter a keyword." class="form-text" /></div>'; ?>
  <?php print $search['search_theme_form']; ?>
  <?php print $search['submit']; ?>
  <?php print $search['hidden']; ?>
</div>

-----
http://kahthong.com - A blog, personal and showcase site
My blog is proudly powered by Drupal CMS

unxposed’s picture

Thanks so much.

This seems to easy! : )

Is this considered best practice?

Thanks!

ktleow’s picture

Not sure about best practices though.. But its easier than creating function overrides, etc etc..
=)

-----
http://kahthong.com - A blog, personal and showcase site
My blog is proudly powered by Drupal CMS