0

I would like to disable the spaces in the usernames. For that I installed a rules module and i applied a rule. Everything is fine but now the label is still saying : "Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores."

How can i change that label ? I looked everywhere and i didn't find a thing.

I am new to drupal. I use drupal 7.

Thanks in advance for you responses.

2 Answers 2

4

Another couple of options using string translation techniques:

  1. Contrib module: String Overrides
  2. settings.php snippet insert

The string overrides module lets you do the string translation via the UI. Otherwise, you can set the override in settings.php - the search string needs to match exactly.

/**
 * String overrides:
 *
 * To override specific strings on your site with or without enabling locale
 * module, add an entry to this list. This functionality allows you to change
 * a small number of your site's default English language interface strings.
 */
$conf['locale_custom_strings_en'][''] = array(
  'Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.' => 'Spaces and punctuation are not allowed except for periods, hyphens, apostrophes, and underscores.',
);
1
  • 1
    The StringOverrides module is awsome. I used it and everything is fine now. Thanks a lot for your answer. Feb 3, 2014 at 7:20
2

The text is in user_account_form function https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_account_form/7

To change it, you can implement a hook_form_alter. I believe the text appears on two forms, 'user_register_form' and 'user_profile_form'. Create a module, put this in it (change mymodule to your module name).

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
    $form['account']['name']['#description'] = t('This will be the new text Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.');
  }
}
2
  • Note, this approach will work but no need to return $form in hook_form_alter as the $form variable is passed by reference . Feb 3, 2014 at 3:24
  • I trust that this is another solution but i did not changed code in drupal since i use drupal, so i tried the StringOverrides module which did the job. Thanks a lot for your answer too. Feb 3, 2014 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.