My users have several options in their user profile edit form page. I would like to customize it by totally removing the following form entries:

  • Interface language settings
  • Group e-mail settings (from mass_mailer)
  • Contact settings
  • Locale settings (the site is useless in other languages than Swedish)

and only keep the possibility to edit Account information.

If it's controllable per theme or per role doesn't really matter. Both will work.

How can I do this?

Comments

olalindberg’s picture

oups.. seems like I missed some HTML-problems.. sorry..

olalindberg’s picture

I think I have a solution that works now. I created a custom module called custom_user_profile_edit_page and put the following code in that module. I enabled the module and the forms don't appear any more.


/**
 * Override the printing of the forms in the user edit page
 */
function custom_user_profile_edit_page_form_alter($form_id, &$form)
{
  // Is it the user_edit form we show
 if($form_id == 'user_edit')
  {
  
    // Some kind of check so we don't unset the wrong variable, probably pretty stupid..
    
    if(is_array($form['mail']['mass_contact_optout']))
    {
      unset($form['mail']);
    }
    
    if(is_array($form['locale']['language']))
    {
      unset($form['locale']);
    }
    
    if(is_array($form['timezone']['timezone']))
    {
      unset($form['timezone']);
    }
    
    if(is_array($form['contact']['contact']))
    {
      unset($form[contact]);
    }
  }
  
  // When we register a new user
  if($form_id == 'user_register')
  {
    if(is_array($form['mail']['mass_contact_optout']))
    {
      unset($form['mail']);
    }
  }
 
}

amcc’s picture

I've made a module with your code, its not working for me. I'm using bio module for my profiles and i've themed the bio edit page fine as it's a node, but i want to also theme the user/[uid]/edit page (to remove most of the stuff you've removed)

The above code isn't working for me though - i've named the module custom_profile.module, created a custom_module.info file and enabled it - fine so far. But nothing seems to be happening.

Is this the standard form id: 'user_edit'
Is there some way doing this for the user form print_r($form) - i'm not sure where to put it though - to find all the form elements

please elaborate on your code if possible, thank you

amcc’s picture

looked around and found a way of getting it to work, if you want to double check elements exist before unsetting them - see above

/**
* Override the printing of the forms in the user edit page
*/
function custom_profile_form_alter($form_id, &$form) {
  if($form_id == 'user_edit' && arg(3) == NULL) {
    // only fire this if it's user/<uid>/edit, not any other category
    unset($form['locale']);
    unset($form['timezone']);
    unset($form['comment_settings']);
    unset($form['contact']);
  }
}
ashokkumarc’s picture

olalindberg ,

i have created module with ur code , but it doesnt working

Help me to solve Modifying the content on the user profile edit form in drupal 6

omnia.ibrahim’s picture

There is a small change in the form id name in drupal 6

try this and it will work:


if ($form_id == 'user_profile_form' && arg(3) == NULL) {
    // only fire this if it's user/<uid>/edit, not any other category
    unset($form['locale']);
    unset($form['timezone']);
}

Ananya MultiTech’s picture

I want to hide name & status field even in case of Administrator having permission 'Administer Users' so that they can not change usernames & status of registered users. This is because I have created a super admin account and want to restrict admin group from doing some things.. Other things worked with your provided code, but this is not happening. Can you please guide me Sir?

**I m on D7.15
**They are using 2 different forms for registration and edit in D7 : user_register_form & user_profile_form. arg(3) is always NULL here. It wasted my lot of time hence mentioning here. I can just check the ID = user_profile_form and thats all..