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.)
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | search_box_2.patch | 1.14 KB | hunmonk |
| #6 | search_box_1.patch | 1.12 KB | chx |
| #4 | search_box_0.patch | 1.29 KB | hunmonk |
| #1 | search_box.patch | 1.08 KB | edmund.kwok |
Comments
Comment #1
edmund.kwok commentedThough 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.
Comment #2
rszrama commentedExcellent. Just noticed that callback_arguments field in the _menu array... thanks for making the patch!
Comment #3
hunmonk commentedcode looks good, patch applies cleanly, fixes the problem--let's get this in!
Comment #4
hunmonk commentedchx noted that we should be using notation in line w/ the current core approach. corrected in this patch.
Comment #5
hunmonk commentedthat above patch has also been tested as working...
Comment #6
chx commentedI just deleted a couple spaces (which I suggested adding, silly me) and it's good to go.
Comment #7
hunmonk commentedwhoops. 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.
Comment #8
rszrama commentedGlad to see this got addressed. Thanks for your work, guys. Patch works fine on my site as well. = )
Comment #9
dries commentedCommitted to CVS HEAD. Thanks.
Comment #10
(not verified) commented