It appears the search block is broken in the latest search.module. The problem is in the following two functions:

<?php

/**
 * Output a search form for the search block and the theme's search box.
 */
function search_box() {
  // Use search_keys instead of keys to avoid ID conflicts with the search block.
  $form[$form_id .'_keys'] = array(
    '#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'));
  // Always go to the search page since the search form is not guaranteed to be
  // on every page.
  $form['#action'] = url('search/node');
  $form['#base'] = 'search_box_form';

  return $form;
}

/**
 * Process a block search form submission.
 */
function search_box_form_submit($form_id, $form_values) {
  return 'search/node/'. trim($form_values[$form_id .'_keys']);
}

search_box() is the form builder function for the block/theme search box, and it's creating a field name based on $form_id which is not passed to this function. So the textbox is really just named _keys instead of search_form_keys or whatever. When you submit, search_box_form_submit() is receiving a value for $form_id, and since it can't find any matching data in $form_values it's just not appending the search terms to search/node/. I see in the search_box() a comment saying this field is generated using $form_id on to avoid conflict, but I just changed the key both here and in search_box_form_submit() to 'search_box_keys' and it works just fine.

I don't know how to make diffs in Windows or if this is necessary for a bug like this, but if this fix doesn't create any problems, it certainly needs to be applied. (Perhaps it would be better to pass get $form_id into the builder function somehow, but I don't see why the field needs to be named based on that.)

Comments

edmund.kwok’s picture

Status: Active » Needs review
StatusFileSize
new1.08 KB

Though replacing both $form_id with 'search_box' works, it would result in the theme search field and block search field having the same id. This would be a problem if the search fields need to be theme separately.

A better solution would be to pass the $form_id argument to the form builder function. The attached patch passes the respective form_id to the search_box callback.

rszrama’s picture

Excellent. Just noticed that callback_arguments field in the _menu array... thanks for making the patch!

hunmonk’s picture

code looks good, patch applies cleanly, fixes the problem--let's get this in!

hunmonk’s picture

StatusFileSize
new1.29 KB

chx noted that we should be using notation in line w/ the current core approach. corrected in this patch.

hunmonk’s picture

that above patch has also been tested as working...

chx’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.12 KB

I just deleted a couple spaces (which I suggested adding, silly me) and it's good to go.

hunmonk’s picture

StatusFileSize
new1.14 KB

whoops. that above patch works, but we're supposed to always have callback arguments as an array, which i erroneously omitted. this patch adds it back in.

once again tested as working.

rszrama’s picture

Glad to see this got addressed. Thanks for your work, guys. Patch works fine on my site as well. = )

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)