The default user registration page in Drupal 7 has fields to enter a username, password and an email address.
I have added some extra fields that show up in this form, but I would like to change the way it is displayed.
For example, I would like to change the order of the form items and add CSS.
Importantly, I would like to change the label that is displayed for Username – I would like it to say “Nickname” instead.
How can I do this?
You can change this on several layers:
Translations:
In settings.php you see some examples already, just add:
$conf[‘locale_custom_strings_en’][”] = array(
‘Username’ => ‘Nickname’,
‘username’ => ‘nickname’,
);
You might want to override more strings, that contain username, such as “The username is invalid”. The UX is bad when you start mixing up these words, so in order to do what you want properly, you will have to change several such strings anyway, even if you go with one of the other options below. Most notably you will need to give the validation and error strings some attention.
This, however, will change “username” to “nickname” sidewide! Also for admins and moderators. This might have unwanted side-effects, based on you broader specs and wishes.
Theme override:
In the template.php, you can override anything that gets passed to screen. In this case, you will need to override the login form template.
The explicit code is too much to type in here. But in rough lines you need to:
hook_theme.Form override:
In your theme and in modules, you can use hook_form_alter to override any theme.
In your theme, you would add to template.php:
Or, if you want more business logic (which does not belong in the theme layer), you’d create a module and add a form_alter there: