Hi,

What would be the easiest way to theme the default search form (/search/node) in Drupal 7?

I'd like to change the title, "Enter your keywords" and the label for the submit button but using _preprocess_search_theme_form doesn't seem to work.

Thanks,

koen

Comments

kpv’s picture

There is no search box any more in D7. Use _preprocess_search_block_form instead. See http://drupal.org/node/254940#search_box

benfarhat’s picture

hi koen try this code ... for me it works :)

function hook_mi_form_alter(&$form, &$form_state, $form_id) { 
  
if ($form_id == 'search_form') {
  
$prompt = t('Enter your keywords'); /* change this $prompt */
$keys = t('search...'); /* and this one */

  $form['basic'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('container-inline')),
  );
  $form['basic']['keys'] = array(
    '#type' => 'textfield',
    '#title' => $prompt,
    '#default_value' => $keys,
    '#size' => $prompt ? 40 : 20,
    '#maxlength' => 255,
  );

  $form['basic']['processed_keys'] = array(
    '#type' => 'value',
    '#value' => array(),
  );
  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('value for search button'), /* take a look here */
  );

   // Advanced search start here hwg!
    $form['advanced'] = array(
      '#type' => 'fieldset',
      '#title' => t('advanced search'),  /* you can change this too */
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#attributes' => array('class' => array('search-advanced')),
    );
    $form['advanced']['keywords'] = array(
      '#prefix' => '<div class="criterion">',
      '#suffix' => '</div>',
    );
    $form['advanced']['keywords']['or'] = array(
      '#type' => 'textfield',
      '#title' => t('OR'),  /* here too */
      '#size' => 30,
      '#maxlength' => 255,
  '#description' => t(''), /* u can add a little description too */
    );
    $form['advanced']['keywords']['phrase'] = array(
      '#type' => 'textfield',
      '#title' => t('ur phrase'),  /* here :) */
      '#size' => 30,
      '#maxlength' => 255,
  '#description' => t(''),
    );
    $form['advanced']['keywords']['negative'] = array(
      '#type' => 'textfield',
      '#title' => t('negative words :)'),  /* and here */
      '#size' => 30,
      '#maxlength' => 255,
  '#description' => t(''),
    );

    // Node types:
    $types = array_map('check_plain', node_type_get_names());
    $form['advanced']['type'] = array(
      '#type' => 'checkboxes',
      '#title' => t('choose types'),  /* another title that u can change */
      '#prefix' => '<div class="criterion">',
      '#suffix' => '</div>',
      '#options' => $types,
    );
    $form['advanced']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('value for advanced search button'),  /* and the last one :) */
      '#prefix' => '<div class="action">',
      '#suffix' => '</div>',
      '#weight' => 100,
    );

    // Languages:
    $language_options = array();
    foreach (language_list('language') as $key => $entity) {
      if ($entity->enabled) {
        $language_options[$key] = $entity->name;
      }
    }
    if (count($language_options) > 1) {
      $form['advanced']['language'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Languages'),
        '#prefix' => '<div class="criterion">',
        '#suffix' => '</div>',
        '#options' => $language_options,
'#description' => t(''),
      );
    }

    $form['#validate'][] = 'node_search_validate';
  }
  
}

ishmael-sanchez’s picture

If you are just changing simple element you could just use something like this

<?php
function THEMENAME_form_alter(&$form, &$form_state, $form_id){
  if (
$form_id == 'search_form'){
     
$form['basic']['keys']['#title'] = 'Tester';
     
$form['basic']['submit']['#value'] = 'Test';
     
dsm($form); // Use for debugging
 
}
}
?>