Hi,
I am trying to use automodal to edit user profile.
I managed to load the user_profile_form form, but whenever I hit the save button, I got the following error:

Notice: Undefined index: user in user_profile_form_submit() (Zeile 307 von /var/www/html/cms/modules/user/user.pages.inc).

I already load user.pages in my modul hook_init:

function ctools_user_edit_init()
{
    form_load_include($form_state, 'inc', 'user', 'user.pages');
//  module_load_include('inc', 'user', 'user.pages');
  global $user;
}

But this even does not help.

My hook_menu is:

function ctools_user_edit_menu() {
  $items = array();

  $items['edit-social'] = array(
    'title' => 'Edit user social links',
    'description' => 'Here are some explanations for the user social edit form',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('ctools_user_edit_contact_us_form'),
    'access arguments' => array('access content'),
  );

  return $items;
}

Comments

vistree’s picture

Issue summary: View changes
wojtha’s picture

@vistree look at #1450372: How to: How to handle two forms in one modal (unified login page) here is working example for register form and signup form both placed in the single modal. It might help.

Regarding the example you posted it seems that form is submitted to the right handler but the form handler is missing 'user' value in the $form_state.

Look here: https://github.com/drupal/drupal/blob/7.x/modules/user/user.pages.inc#L307

If you look in the original form, you'll see the following:

  // During initial form build, add the entity to the form state for use during
  // form building and processing. During a rebuild, use what is in the form
  // state.
  if (!isset($form_state['user'])) {
    $form_state['user'] = $account;
  }
  else {
    $account = $form_state['user'];
  }

Do you have this code inside your ctools_user_edit_contact_us_form function?

vistree’s picture

Hi wojtha,
thank you very much for your feedback. The error has gone. But unfortunately the user edits are not saved.
Comparing the links you sent me, let me ask something: could it be, that I have to use an other page callback?
In the moment, I use 'drupal_get_form'. Is this fine for a user edit form?

wojtha’s picture

It can be many things.... maybe missing category (profile is split to several pages which each represent a 'category'), account, or wrong structure of the form data.

Debug user_profile_form_submit() with dvm() or dpm() to see what is happening. Or create your own validation and submit handlers (copy the body of user_profile_form_validate() and user_profile_form_submit() and tweak them to get 100% control over the form submission.

yogeshchaugule8’s picture

This is older thread, but here is how we can get it working.

1. Implement hook_menu_alter and alter profile edit form to be rendered in ctools modal:

<?php
function MODULENAME_menu_alter(&$items) {
  // Load user edit form in ctools modal.
  $items['user/%user/edit']['modal'] = TRUE;
}
?>

2. Implement hook_form_alter and add following code:

<?php
function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_profile_form') {
    // Make sure to add custom submit handler at same level as User module's submit handler to avoid data not saving issue.
    $form['#submit'][] = '_MODULENAME_user_profile_submit';
  }
}
?>

3. Implement submit handler.

<?php
/**
 * Custom submit handler to profile edit page.
 */
function _MODULENAME_user_profile_submit($form, &$form_state) {
  if ($form_state['submitted']) {
    ctools_include('modal');
    $commands[] = ctools_modal_command_dismiss();
    print ajax_render($commands);
    drupal_exit();
  }
}
?>

NOTE: All of above code will go into the custom module.