You are here

function ctools_context_term_settings_form_validate in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 plugins/contexts/term.inc \ctools_context_term_settings_form_validate()

Validate a term.

File

plugins/contexts/term.inc, line 117
Plugin to provide a term context.

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);
  }
}