You are here

function node_search_validate in Drupal 6

Same name and namespace in other branches
  1. 4 modules/node.module \node_search_validate()
  2. 5 modules/node/node.module \node_search_validate()
  3. 7 modules/node/node.module \node_search_validate()

Form API callback for the search form. Registered in node_form_alter().

1 string reference to 'node_search_validate'
node_form_alter in modules/node/node.module
Implementation of hook_form_alter().

File

modules/node/node.module, line 1932
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Code

function node_search_validate($form, &$form_state) {

  // Initialise using any existing basic search keywords.
  $keys = $form_state['values']['processed_keys'];

  // Insert extra restrictions into the search keywords string.
  if (isset($form_state['values']['type']) && is_array($form_state['values']['type'])) {

    // Retrieve selected types - Forms API sets the value of unselected checkboxes to 0.
    $form_state['values']['type'] = array_filter($form_state['values']['type']);
    if (count($form_state['values']['type'])) {
      $keys = search_query_insert($keys, 'type', implode(',', array_keys($form_state['values']['type'])));
    }
  }
  if (isset($form_state['values']['category']) && is_array($form_state['values']['category'])) {
    $keys = search_query_insert($keys, 'category', implode(',', $form_state['values']['category']));
  }
  if ($form_state['values']['or'] != '') {
    if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state['values']['or'], $matches)) {
      $keys .= ' ' . implode(' OR ', $matches[1]);
    }
  }
  if ($form_state['values']['negative'] != '') {
    if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state['values']['negative'], $matches)) {
      $keys .= ' -' . implode(' -', $matches[1]);
    }
  }
  if ($form_state['values']['phrase'] != '') {
    $keys .= ' "' . str_replace('"', ' ', $form_state['values']['phrase']) . '"';
  }
  if (!empty($keys)) {
    form_set_value($form['basic']['inline']['processed_keys'], trim($keys), $form_state);
  }
}