1

There is a solution for showing the site language selection field on the user/register form in Drupal 6 here: https://stackoverflow.com/questions/5556895/how-to-add-language-switcher-in-user-register-form-in-drupal-6

However, I'm personally not able to convert this to Drupal 7. Is there another way to do this?

EDIT: When multiple languages are enabled via locale, the "Language Settings" with the list of user languages is shown on /admin/people/create. This is what I want-- except I want this to be shown on /user/register, where it is not (at least by enabling locale alone) shown by itself.

1
2

As Drupal 7 doesn't show the language selector for the users who create their own account, you need to implement hook_form_user_register_form_alter() (see the documentation for hook_form_FORM_ID_alter()) using the following code.

function mymodule_form_user_register_form_alter(&$form, &$form_state) {
  // Only alter user forms if there is more than one language.
  if (!isset($form['locale']) && drupal_multilingual()) {
    locale_language_selector_form($form, $form_state, $form['#user']);
  }

  if (isset($form['locale']) { 
    $form['locale']['#access'] = TRUE;
  }
}

The code is generic, and works even in the case a module removed the language selector field (which is something a module should never do, though).

"user_register_form" is the form builder used for the "user/register" path. The code works if the Locale module is enabled. The code will show the language selector if there are more than one language enabled; differently, drupal_multilingual() would return FALSE.

  $items['user/register'] = array(
    'title' => 'Create new account', 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('user_register_form'), 
    'access callback' => 'user_register_access', 
    'type' => MENU_LOCAL_TASK,
  );

The code used from the Locale module is the following one.

function locale_form_alter(&$form, &$form_state, $form_id) {
  // Only alter user forms if there is more than one language.
  if (drupal_multilingual()) {
    // Display language selector when either creating a user on the admin
    // interface or editing a user account.
    if ($form_id == 'user_register_form' || ($form_id == 'user_profile_form' && $form['#user_category'] == 'account')) {
      locale_language_selector_form($form, $form_state, $form['#user']);
    }
  }
}

 

In general, the equivalent for hook_user('register') in Drupal 7 is hook_form_user_register_form_alter(); the equivalent of hook_user('form') is hook_form_user_profile_form_alter().

2
  • Thank you for this. Yes, I have locale enabled, and I do see the choice of user language when creating the user as an admin. What I want to do, however, is alter the form at registration. I will look into hook_form_alter(). – Patrick Kenny Mar 31 '12 at 14:55
  • Follow-up question here: drupal.stackexchange.com/q/27100/5147 – Patrick Kenny Mar 31 '12 at 15:28
0

Yes you can add any kind of field in user registration form using Profile2.

First download the required module and enable the profile 2 module.Then go to "admin/structure" There you will find a option like "Profile types".Click on that, then you will get a form like content type manage field.There you can create selectbox option.

If you need this selectbox should come on the user registration page follow the below steps

  1. Go to "admin/structure/profiles/manage/main"
  2. There you will get a Checkbox, check it to visible the field in registration form
1
  • Sorry, I'm not interested in adding a new field. What I want to do is add the site language select for users-- which already exists in core-- to the user/register form. I tried installing profile2 anyway but there is no option for this. – Patrick Kenny Mar 2 '12 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.