The strings you want to change are the strings used for the #description properties of the name and mail form fields.
// Only show name field on registration form or user can change own username.
$form['account']['name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#maxlength' => USERNAME_MAX_LENGTH,
'#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'),
'#required' => TRUE,
'#attributes' => array(
'class' => array(
'username',
),
),
'#default_value' => !$register ? $account->name : '',
'#access' => $register || $user->uid == $account->uid && user_access('change own username') || $admin,
'#weight' => -10,
);
$form['account']['mail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail address'),
'#maxlength' => EMAIL_MAX_LENGTH,
'#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'),
'#required' => TRUE,
'#default_value' => !$register ? $account->mail : '',
);
You could change those strings by using the String Overrides module (which works for every string passed to t()
, as in this case), implementing hook_form_FORM_ID_alter()
in a module, or implementing hook_form_alter()
.
In the first case, the module would replace every occurrence of the strings, while in the other two cases the strings would be replaced just in a specific form or when other conditions are verified. Since you seem to want to change those strings only when users register their account, I would use hook_form_FORM_ID_alter()
.
As there users who have the permission to change their own usernames, which means the username is not set when an account is created, I would use code similar to the following one.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
global $user;
if ($form_id == 'user_register_form' || ($form_id == 'user_profile_form' && isset($form['#user_category']) && $form['#user_category'] == 'account')) {
// The user is creating a new account or editing an existing account.
if (isset($form_state['user']) && $form_state['user']->uid == $user->uid) {
// The user is creating or editing their own account.
$form['account']['name']['#description'] = t('Your new description for the name field');
$form['account']['mail']['#description'] = t('Your new description for the mail field');
}
}
}
In this way, users who can edit accounts of other users (users with administrative permissions) would see the default description given from Drupal.
hook_form_alter()
is the right option$form['account']['name']['#description']
, but if you install the Devel module and usedpm($form);
in your alter hook, you should be able to find it easily. If not just update the question, it'll be something easily solved