0

I'm trying to change the default descriptions in different pages like (add users). I tried devel themer to find out where there descriptions are came from but it showed nothing. for example look at this picture (add user) :

enter image description here

how do I can change the texts displayed by red line?


Update

I tested this code in template.php

function MYTHEME_form_alter(&$form, &$form_state, $form_id){
if($form_id == "user_register_form"){
    $form['account']['name'] = array(
            '#title' => t('New username'),
            '#description' => t('New description'),
    );
    }
}
4
  • 1
    That's a job for hook_form_alter()
    – Clive
    Commented Apr 28, 2014 at 13:11
  • 1
    Or use String Overrides module if you don't want to do any coding.
    – Felix Eve
    Commented Apr 28, 2014 at 13:22
  • @FelixEve this module is perfect but there is problem with it, fields which are overridden by this module are not displayed in the users that are not admin and are not able to access overlay. (I have set the permission to every one)
    – M a m a D
    Commented Apr 28, 2014 at 13:30
  • I've used that module before to override strings shown to anonymous users (on the login page) so I know it can work...
    – Felix Eve
    Commented Apr 28, 2014 at 13:34

2 Answers 2

1

In your code your overwriting the whole name array - you only want to update 2 properties:

function MYTHEME_form_alter(&$form, &$form_state, $form_id){
  if($form_id == "user_register_form"){
    // Here just target the #title attributes - not the whole name array
    $form['account']['name']['#title'] = t('New username');
    // Same here with description.
    $form['account']['name']['#description'] = t('New description');
  }
}
11
  • thanks. it works perfectly for non-admin user (it is enough for me) but for admin nothing changed. is there any settings or permissions for admin?
    – M a m a D
    Commented Apr 28, 2014 at 13:51
  • How can an admin user see the register form? If they are admin then they are logged in so can't see the register form at all?
    – Felix Eve
    Commented Apr 28, 2014 at 13:53
  • it is add new user form not the registration
    – M a m a D
    Commented Apr 28, 2014 at 13:54
  • And I expect the admin page uses a different theme? So your theme functions are not called on admin pages. Solution here is to move this into a custom module as then it will get called whatever theme is active...
    – Felix Eve
    Commented Apr 28, 2014 at 13:56
  • No, admin only uses overlay for this form but others do not.
    – M a m a D
    Commented Apr 28, 2014 at 13:57
1

you can find the descriptions at user.module under user directory (in modules directory)

you can find those descriptions under user_account_form function

Ex, E-mail address field description below.

$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 : ''),
  );

But it's better to Use hook_form_alter to achieve it

9
  • But don't change the values in the user.module. Use hook_form_alter in your own module.
    – Felix Eve
    Commented Apr 28, 2014 at 13:23
  • where should be this hook_form_alter? in template.php or I should build a module? any difference?
    – M a m a D
    Commented Apr 28, 2014 at 13:24
  • No difference. Any alter hook can be used in template.php or module file.
    – Felix Eve
    Commented Apr 28, 2014 at 13:28
  • @FelixEve I tested it but it didn't work!
    – M a m a D
    Commented Apr 28, 2014 at 13:32
  • 1
    @Drupalist See this answer for updating a confirm_password field.
    – Felix Eve
    Commented Apr 29, 2014 at 8:09

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.