function node_search_validate

Form validation handler for node_form_alter().

1 string reference to 'node_search_validate'
node_form_search_form_alter in modules/node/node.module
Implements hook_form_FORM_ID_alter().

File

modules/node/node.module, line 2884

Code

function node_search_validate($form, &$form_state) {
    // Initialize 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 - Form 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_expression_insert($keys, 'type', implode(',', array_keys($form_state['values']['type'])));
        }
    }
    if (isset($form_state['values']['term']) && is_array($form_state['values']['term']) && count($form_state['values']['term'])) {
        $keys = search_expression_insert($keys, 'term', implode(',', $form_state['values']['term']));
    }
    if (isset($form_state['values']['language']) && is_array($form_state['values']['language'])) {
        $languages = array_filter($form_state['values']['language']);
        if (count($languages)) {
            $keys = search_expression_insert($keys, 'language', implode(',', $languages));
        }
    }
    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']['processed_keys'], trim($keys), $form_state);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.