You are here

function me_admin_settings_form_validate in me aliases 6.2

Same name and namespace in other branches
  1. 8 me.module \me_admin_settings_form_validate()
  2. 6 me.module \me_admin_settings_form_validate()
  3. 7 me.module \me_admin_settings_form_validate()

Validation callback for me_admin_settings_form.

1 string reference to 'me_admin_settings_form_validate'
me_admin_settings_form in ./me.module
Form callback for the admin settings form.

File

./me.module, line 692
Provides 'me' aliases to allow users to enter 'me' in common paths instead of their user id.

Code

function me_admin_settings_form_validate($form, &$form_state) {

  // If the token module is installed, we need to also allow a list of tokens
  // that are allowed to match against. We include all global tokens here, even though
  // some of them don't really make sense, but that is up to the end user.
  $token_list = array();
  if (module_exists('token')) {
    $tkl = token_get_list('global');
    foreach ($tkl as $tl) {
      $token_list = array_merge($token_list, array_map(create_function('$n', 'return "[$n]";'), array_keys($tl)));
    }
  }
  if (preg_match('/[^a-zA-Z-]/', $form_state['values']['me_alias']) && !in_array($form_state['values']['me_alias'], $token_list)) {
    if (!empty($token_list)) {
      $message = t('The alias can only contain characters from a-z and A-Z, or one of the tokens specified in the "Replacement patterns for me alias" section.');
    }
    else {
      $message = t('The alias can only contain characters from a-z and A-Z.');
    }
    form_set_error('me_alias', $message);
  }
}