Profile edit form on same page as account information

Sometimes, you need to merge user account edit screen and profile values to one form. Here is a snippet how to do it.

Example:
You want to merge User edit form with My personal data section of the profile.

First, you need to create your own module. Implement hook_user():

/*
* Implementation of hook_user().
*/
function mymodule_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'form':
      // We are at edit screen. Load form data for "My personal data" category.
      return profile_form_profile($edit, $user, 'My personal data');
      break;
  }
}

Code above will merge these two forms together and display profile form on user edit screen.

It does work, but...

morthylla - July 21, 2009 - 14:23

If there are more profile forms, the hook_user will add our 'My personal data' form to all profile sections. In order to avoid that it is possible to use this version of _user

/*
* Implementation of hook_user().
*/
function etsf_personal_info_user($op, &$edit, &$account, $category = NULL) {
  if ($op == 'form' && $category == 'account') {
    // We are at edit screen. Load form data for 'My personal data' category.
    return profile_form_profile($edit, $user, 'My personal data');
    break;
  }
}

The only problem I have now is that the original 'My personal data' form is still displayed. I want to hide it.

In any case, thank you!

The only problem I have now

bocky - August 11, 2009 - 11:10

The only problem I have now is that the original 'My personal data' form is still displayed. I want to hide it.

You can hide it with

ul.secondary {
display:none;
}

However this will hide all secondary tabs.

You could also use custom template page-user-edit.tpl and comment out

<?php if ($tabs): print '<div id="tabs-wrapper" class="clear-block">'; endif; ?>
<?php if ($tabs): print '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
<?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>

One Page Profile module

chirale - October 9, 2009 - 14:56

There is this useful module:

http://drupal.org/project/onepageprofile

that do the same in a better way.

Note that snippets in this page aren't working: they works only apparently, but all data are stored on $account->data instead of on {profile_values} database table (I've tested it directly adapting these snippets to Drupal 5.x, but not on 6.x).

That module solves this kind of issue, and many others are listed on issue queue http://drupal.org/project/issues/onepageprofile.

subscribing...

mortenson - November 15, 2009 - 18:47

subscribing...

Can it be implemented with Content Profile?

dynlist - November 16, 2009 - 04:19

I'm using Content Profile module to add extra CCK fields to the profile (Drupal 6.x). How can I merge it with the Account Information page?

Thanks a lot!

 
 

Drupal is a registered trademark of Dries Buytaert.