You are here

function locale_add_language_form_validate in Drupal 5

Same name and namespace in other branches
  1. 4 includes/locale.inc \locale_add_language_form_validate()

Validate the language addition form.

File

includes/locale.inc, line 192
Admin-related functions for locale.module.

Code

function locale_add_language_form_validate($form_id, $form_values) {
  if ($duplicate = db_num_rows(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $form_values['langcode'])) != 0) {
    form_set_error(t('The language %language (%code) already exists.', array(
      '%language' => $form_values['langname'],
      '%code' => $form_values['langcode'],
    )));
  }

  // If we are adding a non-custom language, check for a valid langcode.
  if (!isset($form_values['langname'])) {
    $isocodes = _locale_get_iso639_list();
    if (!isset($isocodes[$form_values['langcode']])) {
      form_set_error('langcode', t('Invalid language code.'));
    }
  }
  else {
    if (preg_match('/["<>\']/', $form_values['langcode'])) {
      form_set_error('langcode', t('The characters &lt;, &gt;, " and \' are not allowed in the language code field.'));
    }
    if (preg_match('/["<>\']/', $form_values['langname'])) {
      form_set_error('langname', t('The characters &lt;, &gt;, " and \' are not allowed in the language name in English field.'));
    }
  }
}