function search_form

You are here

7 search.module search_form($form, &$form_state, $action = '', $keys = '', $module = NULL, $prompt = NULL)
4.6 search.module search_form($action = '', $keys = '', $type = null, $prompt = null)
4.7 search.module search_form($action = '', $keys = '', $type = NULL, $prompt = NULL)
5 search.module search_form($action = '', $keys = '', $type = NULL, $prompt = NULL)
6 search.module search_form(&$form_state, $action = '', $keys = '', $type = NULL, $prompt = NULL)

Render a search form.

Parameters

$action: Form action. Defaults to "search".

$keys: The search string entered by the user, containing keywords for the search.

$type: The type of search to render the node for. Must be the name of module which implements hook_search(). Defaults to 'node'.

$prompt: A piece of text to put before the form (e.g. "Enter your keywords")

Return value

A Form API array for the search form.

Related topics

4 string references to 'search_form'
node_form_alter in modules/node/node.module
Implementation of hook_form_alter().
search_view in modules/search/search.pages.inc
Menu callback; presents the search form and/or search results.
template_preprocess_search_block_form in modules/search/search.module
Process variables for search-block-form.tpl.php.
template_preprocess_search_theme_form in modules/search/search.module
Process variables for search-theme-form.tpl.php.

File

modules/search/search.module, line 1022
Enables site-wide keyword searching.

Code

function search_form(&$form_state, $action = '', $keys = '', $type = NULL, $prompt = NULL) {

  // Add CSS
  drupal_add_css(drupal_get_path('module', 'search') . '/search.css', 'module', 'all', FALSE);

  if (!$action) {
    $action = url('search/' . $type);
  }
  if (is_null($prompt)) {
    $prompt = t('Enter your keywords');
  }

  $form = array(
    '#action' => $action,
    '#attributes' => array('class' => 'search-form'),
  );
  $form['module'] = array(
    '#type' => 'value',
    '#value' => $type,
  );
  $form['basic'] = array(
    '#type' => 'item',
    '#title' => $prompt,
    '#id' => 'edit-keys',
  );
  $form['basic']['inline'] = array(
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $form['basic']['inline']['keys'] = array(
    '#type' => 'textfield',
    '#title' => '',
    '#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']['inline']['processed_keys'] = array(
    '#type' => 'value',
    '#value' => array(),
  );
  $form['basic']['inline']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );

  return $form;
}