function search_form

Form constructor for the 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.

See also

search_form_validate()

search_form_submit()

Related topics

1 string reference to 'search_form'
search_view in drupal/core/modules/search/search.pages.inc
Page callback: Presents the search form and/or search results.

File

drupal/core/modules/search/search.module, line 950
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',
      ),
    ),
  );
  $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']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );
  return $form;
}