You are here

function location_taxonomize_form_validate in Location Taxonomize 7.2

Same name and namespace in other branches
  1. 7 location_taxonomize.admin.inc \location_taxonomize_form_validate()

Validation hook for the module's admin form

File

./location_taxonomize.admin.inc, line 464
Contains the admin forms for Location Taxonomize

Code

function location_taxonomize_form_validate($form, &$form_state) {
  $values = $form_state['values'];

  //  if we're initializing, make sure that there are no interfering vocabs
  $state = $values['location_taxonomize_vocab']['state'];
  switch ($state) {
    case 'initialization':
      $values_init = $values['location_taxonomize_vocab'];
      $vid = variable_get('location_taxonomize_vid');
      if ($vid) {
        form_set_error('', t('There seems to already be a Vocabulary
                              associated with Location Taxonomize.'));
      }
      $vocab = taxonomy_vocabulary_machine_name_load(LT_VOCAB_NAME);
      if ($values_init['method'] == 'new' && $vocab) {
        form_set_error('', t("Could not create new Location Taxonomy vocabulary.\n                       A vocabulary with the name '@name' already exists.", array(
          '@name' => LT_VOCAB_NAME,
        )));
      }
      if ($values_init['method'] == 'existing') {
        if (!$vocab) {
          form_set_error('', t("Could not use the existing vocabulary.\n                                    There is no existing vocabulary with the name\n                                    '@name'", array(
            '@name' => LT_VOCAB_NAME,
          )));
        }
        elseif ($vocab->vid != $values_init['possible_vid']) {
          form_set_error('', t('Could not use the existing vocabulary (vid @vid). Wrong vid.', array(
            '@vid' => $values_init['possible_vid'],
          )));
        }
      }
      break;
    case 'settings':

      // if the Long Name option is on, the Separator field is required
      $longname_enabled = $form_state['values']['location_taxonomize_settings']['longname_enable'];
      $separator_empty = empty($form_state['values']['location_taxonomize_settings']['longname']['separator']);
      if ($longname_enabled && $separator_empty) {
        form_set_error('location_taxonomize_settings][longname][separator', t('Separator field is required.'));
      }
      break;
  }
}