You are here

function taxonomy_manager_form_validate in Taxonomy Manager 5

Same name and namespace in other branches
  1. 6.2 taxonomy_manager.admin.inc \taxonomy_manager_form_validate()
  2. 6 taxonomy_manager.admin.inc \taxonomy_manager_form_validate()
  3. 7 taxonomy_manager.admin.inc \taxonomy_manager_form_validate()

validates the form

File

./taxonomy_manager.module, line 878
Taxonomy Manager

Code

function taxonomy_manager_form_validate($form_id, $form_values) {
  $selected_tids = array();
  $selected_tids = $form_values['taxonomy']['manager']['tree']['selected_terms'];
  switch ($form_values['op']) {
    case t('Add'):

      //check for parents concerning voc settings
      $voc = taxonomy_get_vocabulary($form_values['vid']);
      if ($voc->hierarchy == 0 && count($selected_tids) > 0) {
        form_set_error('add', t('Please unselect terms in the list before adding new terms. This vocabulary doesn\'t provide hierarchies.'));
      }
      else {
        if ($voc->hierarchy == 1 && count($selected_tids) > 1) {
          form_set_error('add', t('Please only select one term in the list (at maximum) as parent. This vocabulary provides only single hirarchies.'));
        }
      }
      break;
    case t('Merge'):
      $main_terms = array();
      $regexp = '%(?:^|,\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
      preg_match_all($regexp, $form_values['merge']['main_term'], $matches);
      $main_terms = $matches[1];
      if (!is_array($main_terms) || count($main_terms) == 0 || empty($main_terms[0])) {
        form_set_error('merge][main_term', t("Please enter a name into %title", array(
          '%title' => "'" . t('Main term') . "'",
        )));
      }
      else {
        if (count($main_terms) > 1) {
          form_set_error('merge][main_term', t("Please only enter single names into %title", array(
            '%title' => "'" . t('Main term') . "'",
          )));
        }
      }
      if (count($selected_tids) < 1) {
        form_set_error('merge', t("Please selected terms you want to merge"));
      }
      else {
        if (count($selected_tids) > 50) {
          form_set_error('merge', t("Please select less than 50 terms to merge. Merging to many terms in one step can cause timeouts and inconsistent database states"));
        }
      }
      break;
    case t('Move'):
      if (count($selected_tids) < 1) {
        form_set_error('move', t("Please selected terms you want to move in the hierarchy"));
      }
      break;
  }
}