2

I'm trying to send user edit page to the user profile page (/user), so I can get user profile informations and user edit form on the same page.

function hook_preprocess_user_profile(&$vars) {
  global $user;
  $account = user_load($user->uid);
  $vars['form'] = drupal_get_form('user_profile_form', $account);
}

Then in user-profile.tpl.php I have the following :

<?php print drupal_render($form['field_user_address']); ?>
<?php // Print necessary validation fields and remove others
      unset($form['field_user_society_id']);
      unset($form['field_user_locations']);
      unset($form['locale']);
      unset($form['account']);
      print drupal_render($form);
 ?>

It works well, I have my form, the datas are coming into it but when saving it, even if I get status message "Changes have been saved" actually no datas are saved.

I tried to put module_load_include('inc', 'user', 'user.pages');in a hook_init() and in a form_alter, but no way to get the form datas saved.

Thanks for helping.

5
  • Could it be because 'account' is being removed?
    – Kevin
    May 1 '18 at 17:49
  • Sorry, I had forgottent some infos. $account is just a var for user_load.
    – Aporie
    May 1 '18 at 17:59
  • You could try hook_url_inbound_alter and hook_url_outbound_alter for 'faking' front-end paths. It would allow you to serve the form under a different url. But I am not sure if it overrides hook_menu. Otherwise you would have to use hook_menu_alter to remove the user path, but then you will probably run into weird issues where user/login and user/logout are no longer available. May 1 '18 at 18:10
  • Actually my users get logged through a oauth2 api. What I need is to get the user profile information and the user edit form on the same page. So It's not about a url problem :). Thanks for helping.
    – Aporie
    May 1 '18 at 18:12
  • @Aporie, that is quite an important detail :) I assumed you wanted to replace the profile information entirely. Could you edit it into the question? May 1 '18 at 18:14
0

So, the solution was quite simple.

I just needed to remove the call to $form['field_user_address']

//<?php print drupal_render($form['field_user_address']); ?>
<?php // Print necessary validation fields and remove others
      unset($form['field_user_society_id']);
      unset($form['field_user_locations']);
      unset($form['locale']);
      unset($form['account']);
      print drupal_render($form);
 ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.