You are here

function auto_username_settings_form_validate in Automatic User Names 7

Validate auto_username_settings_form form submissions.

File

./auto_username.admin.inc, line 185
Form builder; displays the auto_username settings form.

Code

function auto_username_settings_form_validate($form, &$form_state) {
  module_load_include('inc', 'auto_username');

  // Perform a basic check for HTML characters in the strings to remove field.
  if (strip_tags($form_state['values']['aun_ignore_words']) != $form_state['values']['aun_ignore_words']) {
    form_set_error('aun_ignore_words', t('The <em>Strings to remove</em> field must not contain HTML. Make sure to disable any WYSIWYG editors for this field.'));
  }

  // Validate that the separator is not set to be removed.
  // This isn't really all that bad so warn, but still allow them to save the value.
  $separator = $form_state['values']['aun_separator'];
  $punctuation = auto_username_punctuation_chars();
  foreach ($punctuation as $name => $details) {
    if ($details['value'] == $separator) {
      $action = $form_state['values']['aun_punctuation_' . $name];
      if ($action == AUN_PUNCTUATION_REMOVE) {
        drupal_set_message(t('You have configured the @name to be the separator and to be removed when encountered in strings. You should probably set the action for @name to be "replace by separator".', array(
          '@name' => $details['name'],
        )), 'error');
      }
    }
  }
}