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.

EDIT:
As the comments will tell: DO NOT USE THIS HACK!
Instead use for example the module "onepageprofile"

The problem is that it stores the data in the account (table: users) instead of in the profile (table: profile_values)

Comments

morthylla’s picture

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!

bocky’s picture

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; ?>
davegan’s picture

This can be solved by creating a custom module and using hook_menu_alter

function mymodule_menu_alter(&$items) {
  $items['user/%user_category/edit/My personal data']['type'] = MENU_CALLBACK;
}

This will remove the tab for your profile category 'My personal data'.

chirale’s picture

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.

rosell.dk’s picture

Thanks for that very helpful comment. I would have wished I saw it before I made a module based on this hack...

As there isn't a way to make your comment more visible, I will make some noise:

DO NOT USE THE HACK ON THIS PAGE!

I repeat:

DO NOT USE THE HACK ON THIS PAGE!

rosell.dk’s picture

And now, that this is done, I feel safe posting a modified script that deals with the other problems noted in this article. Not to be used, but to be learned from

/*
* Implementation of hook_user().
*/
function profile_on_user_tab_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'form':
      if ($category == "account") {  // This makes sure that the content only is written to the Edit tab
        $data = _profile_on_user_get_profile_categories();
        $form[] = array();
        foreach ($data as $cat) {
          $form = array_merge($form, profile_form_profile($edit, $user, $cat));
        }
        return $form;
      }
      break;
  }
}

/**
 * Implementation of hook_menu_alter().
 */
function profile_on_user_tab_menu_alter(&$items) {
  $data = _profile_on_user_get_profile_categories();
  foreach ($data as $category) {
    $items['user/%user_category/edit/' . $category]['type'] = MENU_CALLBACK;
  }
}

/**
 * Private function to get names of all categories
 */
function _profile_on_user_get_profile_categories() {
  $result = db_query("SELECT DISTINCT(category) FROM {profile_fields}");
  $data = array();
  while ($category = db_fetch_object($result)) {
    array_push($data, $category->category);
  }
  return $data;
}

To repeat:
Do not use the code, as it stores data the wrong place

dynlist’s picture

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!

josepvalls’s picture

I'm looking for the same.
I also wanted to make the Edit tab in the user account to edit the Content profile by default.
Any ideas?

mortenson’s picture

How to display the profile photo field on the page when creating a new account?

witzel’s picture

Same wish here. It would be great if my users could change their account data and the 'content profile' data in the same form.

hey_germano’s picture

There's a module called content_profile_edit posted here - http://drupal.org/node/586464 - that almost does the job, but it needs some help. If you enable this, your Content Profile fields show up on the same page as your account info when editing; however, there's a bug that's keeping it from saving changes properly.

If you comment out the last function on the module (content_profile_edit_user_modify_submit), it works if your edit was a Content Profile field. But account info edits don't save. If you leave that function in place, the opposite happens.

So I think it's close? I'm trying to figure this out (trial and error style), but if somebody a little more skilled at PHP checks it out, I bet we could get this working.