function ctools_context_term_settings_form_validate

Validate a term.

File

plugins/contexts/term.inc, line 117

Code

function ctools_context_term_settings_form_validate($form, &$form_state) {
    // Validate the autocomplete.
    $vid = $form_state['values']['vid'];
    if (empty($form_state['values']['tid']) && empty($form_state['values']['taxonomy'][$vid])) {
        form_error($form['taxonomy'][$vid], t('You must select a term.'));
        return;
    }
    if (empty($form_state['values']['taxonomy'][$vid])) {
        return;
    }
    $term = db_query('SELECT tid FROM {taxonomy_term_data} WHERE LOWER(name) = LOWER(:name) AND vid = :vid', array(
        ':name' => $form_state['values']['taxonomy'][$vid],
        ':vid' => $vid,
    ))->fetchObject();
    if (!$term) {
        form_error($form['taxonomy'][$vid], t('Invalid term selected.'));
    }
    else {
        form_set_value($form['tid'], $term->tid, $form_state);
    }
}