1

I want to change the markup on the user registration form that reads

Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.

and

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.

to something more friendly.

I don't think String Overrides works with the registration form so I guess I need a custom module - hook_form_alter perhaps?

3
  • Yes, hook_form_alter() is the right option
    – Clive
    Commented Dec 2, 2014 at 10:10
  • Thanks - but I am not sure how to target the markup? Commented Dec 2, 2014 at 10:11
  • Off the top of my head it'll be in something like $form['account']['name']['#description'], but if you install the Devel module and use dpm($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
    – Clive
    Commented Dec 2, 2014 at 10:24

3 Answers 3

2

You can do that by implementing hook_form_alter() in your custom module:

For ex:

function MODULE_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'user_register_form') {
    //dpm($form);
    $form['account']['name']['#description'] = t('Your Custom Text');
  }
}

To add Markup you should look into theme_form_element.

0
1

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.

0

There is also the Better Login module which can speed things along for you.

Fancy login forms for Drupal :).

Styling Drupal login/password/registration forms are a mission most of the time because they form part of the theme... This module removes that issue, it is slightly inspired by the way Wordpress login forms work, and uses three page templates to change the style of the forms. It is very simple to use, just install the Better Login module and it starts working immediately.

0

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.