You are here

function ctools_context_term_settings_form_validate in Chaos Tool Suite (ctools) 6

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

Validate a term.

1 string reference to 'ctools_context_term_settings_form_validate'
term.inc in plugins/contexts/term.inc
Plugin to provide a term context

File

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

Code

function ctools_context_term_settings_form_validate($form, &$form_values, &$form_state) {

  // Validate the autocomplete
  $vid = $form_values['vid'];
  if (empty($form_values['tid']) && empty($form_values['taxonomy'][$vid])) {
    form_error($form['taxonomy'][$vid], t('You must select a term.'));
    return;
  }
  if (empty($form_values['taxonomy'][$vid])) {
    return;
  }
  $term = db_fetch_object(db_query("SELECT t.tid FROM {term_data} t WHERE LOWER(t.name) = LOWER('%s') AND t.vid = %d", $form_values['taxonomy'][$vid], $vid));
  if (!$term) {
    form_error($form['taxonomy'][$vid], t('Invalid term selected.'));
  }
  else {
    form_set_value($form['tid'], $term->tid, $form_state);
  }
}