1 search.module | search_form($form, &$form_state, $action = '', $keys = '', $module = NULL, $prompt = NULL) |
Builds a search form.
Parameters
$action: Form action. Defaults to "search/$path", where $path is the search path associated with the module in its hook_search_info(). This will be run through url().
$keys: The search string entered by the user, containing keywords for the search.
$module: The search module to render the form for: a module that implements hook_search_info(). If not supplied, the default search module is used.
$prompt: Label for the keywords field. Defaults to t('Enter your keywords') if NULL. Supply '' to omit.
Return value
A Form API array for the search form.:
Related topics
File
- core/
modules/ search/ search.module, line 1017 - Enables site-wide keyword searching.
Code
function search_form($form, &$form_state, $action = '', $keys = '', $module = NULL, $prompt = NULL) {
$module_info = FALSE;
if (!$module) {
$module_info = search_get_default_module_info();
}
else {
$info = search_get_info();
$module_info = isset($info[$module]) ? $info[$module] : FALSE;
}
// Sanity check.
if (!$module_info) {
form_set_error(NULL, t('Search is currently disabled.'), 'error');
return $form;
}
if (!$action) {
$action = 'search/' . $module_info['path'];
}
if (!isset($prompt)) {
$prompt = t('Enter your keywords');
}
$form['#action'] = url($action);
// Record the $action for later use in redirecting.
$form_state['action'] = $action;
$form['module'] = array('#type' => 'value', '#value' => $module);
$form['basic'] = array('#type' => 'container', '#attributes' => array('class' => array('container-inline')));
// This field is not required because it may be populated by the advanced
// search fields provided by other modules (such as node module).
$form['basic']['keys'] = array(
'#type' => 'search',
'#title' => $prompt,
'#default_value' => $keys,
'#size' => $prompt ? 40 : 20,
'#maxlength' => 255,
);
// processed_keys is used to coordinate keyword passing between other forms
// that hook into the basic search form.
$form['basic']['processed_keys'] = array('#type' => 'value', '#value' => '');
$form['basic']['actions'] = array('#type' => 'actions');
$form['basic']['actions']['submit'] = array('#type' => 'submit', '#value' => t('Search'));
return $form;
}