Customizing ‘edit user’ page in Drupal 7

Step 1.

Tell template.php to use your own template located inside your theme folder YOURTHEME/templates/user-profile-edit.tpl.php


function YOURTHEME_theme() {
return array(
// The form ID.
'user_profile_form' => array(
// Forms always take the form argument.
'arguments' => array('form' => NULL),
'render element' => 'form',
'template' => 'templates/user-profile-edit',
),
);
}

Step 2.

Create sites/all/themes/YOURTHEME/templates/user-profile-edit.tpl.php


print render($form['form_id']);
print render($form['form_build_id']);
print render($form['form_token']);

print render ($form[‘field_user_firstname’]);
print render ($form[‘field_user_lastname’]);
print render ($form[‘field_user_dob’]);

<input type=”submit” name=”op” id=”edit-submit” value=”Save”Ā  />

Step 3.

Customize the CSS to design the form the way you want

I plan on using this to make a multi-page edit form. I will be breaking down the different user fields based on category rather than just dumping everything into one long and boring form.

Hope someone finds this helpful. I’ll be posting more sample codes as I continue to build my website

21 Comments

Filed under Drupal 7, Drupal Theming

21 responses to “Customizing ‘edit user’ page in Drupal 7

  1. Artur

    Thanks for the post! It really helped me out!

  2. how to get the user picture field…

  3. stomerfull

    not working for me i follow all step descibe below but its not working where i go to

    user/me/edit URL

    thank you for your help

  4. stomerfull

    Is anyone can help me ?

  5. stomerfull

    this code snippet is not working in drupal 7 plaese help

  6. blupp42Michael

    Hmmm, I also can’t get it to work. I have checked user.module to see what it does when someone accesses path user/%user/edit and it basically does a drupal_get_form(‘user_profile_form’, $uid).
    And I can’t find any $form[‘#theme’] in user_profile_form() which would then make use of the template file. So I’m a little bit lost here.
    Is there perhaps something else missing?
    Thanks

    • astanley86

      I’ll look into this and get back to you. I posted this a really long time ago so it is possible with the latest upgrades to Drupal 7, they have changed how the backend is delivered. What specifically are you trying to do?

      • I am trying to modify some of the wording on the user edit form but its not usering the user_profile_form that I specify with templates/user-profile-edit

  7. are you sure it’s called user_profile_form in drupal 7 ? its not picking it up

  8. Sarath Rajan

    Hi.. This is an excellent page.. But still I want to know how to print the email field as well as as password fields separately. tried print render ($form[‘mail’]); but of no use šŸ˜¦

  9. Sarath Rajan

    I got it

    print render($form[‘account’][‘mail’]);

    šŸ™‚

  10. I was able to customize the profile edit page but the submitted form doesn’t appear to register. is there a function I should change in the templates file? I’m using drupal 7.

  11. Pingback: [Drupal]All about theming | jolam

  12. Tim

    Please try refreshing the ‘theme registry’ cache.

  13. Gaurav

    thanx. it helped me a lot.

  14. Sergey

    Hello, when i click save, nothing happens, fields have old values. What is the cause? Pls help.

  15. Alex

    It’s working with Drupal 7 as well, but not for user 1.

  16. Vidushi

    This is very nice. I wanted to know if we can hide edit user profile anyhow.
    I wanted to hide email, password, timezone each filed in Drupal-7 for some of specified user role.

    I tried these two functions in my new custom module called first, but no luck:
    —————————
    function first_alter(&$form, &$form_state, $form_id) {
    // changed form id
    if ($form_id === ‘user_form’ AND $account->uid == 178) {
    // Use var_dump to dump the $form array to see the fields.
    var_dump ($form);

    hide($form[‘account’][‘pass’]);
    hide($form[‘account’][‘current_pass_required_values’]);
    hide($form[‘account’][‘current_pass’]);
    }
    }

    ————————–
    function first_form_user_profile_form_alter(&$form, &$form_state) {
    global $user;
    if(in_array(‘enrolled student’,$user->roles)) {
    $form[‘account’][‘pass’][‘#access’] = FALSE;
    // Similarly other fields, but fields can not be required fields on profile.
    }
    }

    hide($user_profile[‘summary’][‘member_for’]);

Leave a comment