/*
* create search block
*/
function mymodule_block_info() {
$blocks['my_search'] = array(
'info' => t('My Search Block'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
function mymodule_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'my_search':
$block['title'] = 'MyCustom Search';
$srchblk = drupal_get_form('mymodule_search_block_form');
$block['content'] = drupal_render($srchblk);
break;
}
return $block;
}
/* create search form */
function mymodule_search_block_form($form, &$form_state) {
$form['keys'] = array(
'#type' => 'textfield',
'#size' => 15,
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Search',
);
return $form;
}
/*
* create search result menu callback
*/
function mymodule_menu() {
$items['custom/node/search/%'] = array(
'page callback' => 'mymodule_do_search',
'page arguments' => array(3),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/*
* create form handler
*/
function mymodule_search_block_form_submit($form, &$form_state) {
drupal_goto('custom/node/search/' . $form_state['values']['keys']);
}
/*
* create search result callback function
*/
function mymodule_do_search($keys) {
// set the page title
drupal_set_title('MY search results');
// get the search results
$results = module_invoke('node', 'search_execute', $keys );
return theme('search_results', array('results' => $results));
}