How to set up a default user registration page in Drupal 7

The default user registration page in Drupal 7 contains fields for entering a username, password, and email address.

I have added a few additional fields that appear on this form, but I would like to change the way I display them.

For example, I would like to reorder form elements and add CSS.

It’s important to note that I would like to change the shortcut displayed for the username - I would like for him to say “Nick”.

How can i do this?

+3
source share
4 answers

You can change this at several levels:

Translations:

In settings.php you already see some examples: just add:

$conf ['locale_custom_strings_en'] [''] = (  'Username' = > 'Nickname',  'username' = > 'nickname', );

, , , " ". UX , , , , , , . .

, , " " "" ! . , .

:

template.php , . .

. :

  • Drupal, hook_theme.
  • . HTML-, .

:

hook_form_alter, .

template.php:

function your_template_form_user_register_form_alter(&$form, &$form_state, $form_id) {
    $form['account']['name']['#title'] = t('Nickname');
}

, - ( ), form_alter :

function your_modulename_form_user_register_form_alter(&$form, &$form_state, $form_id) {
    if (_your_module_is_person_from_irc()) {
      $form['account']['name']['#title'] = t('Nickname');
    }
}
+6

, .

, , .

, drupal http://drupal.stackexchange.com, , .

!

+1

template.php :

function [YOUR-TEMPLATE-NAME]_form_user_register_form_alter(&$form, &$form_state, $form_id) {

    $form['account']['name']['#title'] = t('Nickname');

}

, , print_r($form); .

+1

.

, user_register_submit user_register_form.

The easiest and most flexible solution I have found is to get form data (username, email address and password) through ajax / jquery and create a custom module that programmatically saves data to a new user.

In fact, I find that most often it’s not faster to just go around the “drupal path” through ajax / custom modules than to try to understand layers and layers of legacy code.

And this comes from a guy who started drupaling without prior knowledge of php.

0
source

All Articles