In a comment you said you wanted to replace the string for the error message "The name [username] is not allowed." That error message is returned only from Drupal 6 core, or from a Drupal 7 module; the function that in Drupal 6 shown that error has been removed from Drupal 7, together the functionality of allowing/not allowing some usernames. Drupal 7 can disallow some IPs from being used when accessing a Drupal site.
In Drupal 6, the function showing that error message is user_admin_access_check_submit(), which contains the following code.
switch ($form_state['values']['type']) {
case 'user':
if (drupal_is_denied('user', $form_state['values']['test'])) {
drupal_set_message(t('The username %name is not allowed.', array('%name' => $form_state['values']['test'])));
}
else {
drupal_set_message(t('The username %name is allowed.', array('%name' => $form_state['values']['test'])));
}
break;
// …
}
The same message is shown at least from the User restrictions module, which is the third-party module that implements the functionality that has been removed from Drupal 6. I am one of the maintainers of that module, even though I didn't touch its code from months.
To change that message I would implement hook_form_alter()
to add a new validation handler that alters the error message, if the error message is shown during the validation of a form, or to add a new form submission handler, if the error message is shown during the submission of a form.
In both the cases:
The messages set with drupal_set_message() are saved in $_SESSION['messages'][$type]
, where $type
is status, error, or warning. Keep in mind you don't see the string 'The username %name is not allowed.'
but the string where %name is already replaced with the username. You would need a regular expression to find that message, and replace it with the string you prefer.
The error messages set with form_set_error() are returned from $errors = &drupal_static('form_set_error, array());. The array follows the format
$error[$field_name] = $error_message`. Also in this case, the string you are looking for contains the username, and you need to user a regular expression to find the error message. You need to alter this array if the error message is set in a form validation handler.
Keep in mind that:
The error message, in Drupal 6, and the User restrictions module, doesn't mean the username contains spaces when it should not. It means there is a rule that doesn't allow a user to use a specific username; for example, there could be a rule that disallow usernames matching fun%boy (it's a regular expression used from MySQL, and other database engines), and the error message would appear when the username is fun boy, fun-boy, fund boy, or funxxxxxxxboy.
In Drupal 7, spaces in usernames are allowed; they are not allowed at the beginning of the username, at the end of the username, or when there are 2 or more spaces in row.