You are here

function location_taxonomize_form_validate in Location Taxonomize 7

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

Validation hook for the module's admin form

File

./location_taxonomize.admin.inc, line 331
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'];
  if ($state == '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(LOCATION_TAXONOMIZE_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' => LOCATION_TAXONOMIZE_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' => LOCATION_TAXONOMIZE_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'],
        )));
      }
    }
  }

  // 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.'));
  }
}