Community Documentation

locale_add_language_form_validate

5 locale.inc locale_add_language_form_validate($form_id, $form_values)

Validate the language addition form.

File

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

Code

<?php
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.'));
    }
  }
  // Otherwise, check for invlaid characters
  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.'));
    }
  }
}
?>
Login or register to post comments