You are here

function taxonomy_manager_tree_validate in Taxonomy Manager 7

Same name and namespace in other branches
  1. 5 taxonomy_manager.module \taxonomy_manager_tree_validate()
  2. 6.2 taxonomy_manager.module \taxonomy_manager_tree_validate()
  3. 6 taxonomy_manager.module \taxonomy_manager_tree_validate()

validates submitted form values checks if selected terms really belong to initial voc, if not --> form_set_error

if all is valid, selected values get added to 'selected_terms' for easy use in submit

Parameters

$form:

1 string reference to 'taxonomy_manager_tree_validate'
taxonomy_manager_element_info in ./taxonomy_manager.module
Implements hook_elements().

File

./taxonomy_manager.module, line 926
Taxonomy Manager

Code

function taxonomy_manager_tree_validate($form, &$form_state) {
  $selected = array();

  //this can be useful for more complex processing, where the parent of the selecte term in the tree view is need (releveant if multi parent)

  //used in double tree
  $direct_parents = array();
  $selected = _taxonomy_manager_tree_get_selected_terms($form['#value'], $direct_parents);
  if (!$form['#multiple'] && count($selected) > 1) {

    // There should only be one selected term here. Make sure this is the case.
    $selected = array(
      key($selected) => key($selected),
    );
  }
  $vid = $form['#vid'];
  foreach ($selected as $tid) {
    if (!_taxonomy_manager_tree_term_valid($tid, $vid)) {
      form_set_error('', t('An illegal choice has been detected. Please contact the site administrator.'));
    }
  }
  form_set_value($form, array(
    'selected_terms' => $selected,
    'selected_terms_direct_parents' => $direct_parents,
  ), $form_state);
}