There is a problem with the way profile2_regpath attaches fields to user register form.
One case is described here http://drupal.org/node/1440738#comment-5993478 but I think that a lot of situations where the form is altered through AJAX may experience this kind of annoyances. The effect is that after adding or removing fields to the form dynamically you can loose all the 'profile section' of the form array. The source of the problem is in the way _get_profile_types_by_path() works. In the above described situations it returns nothing

function profile2_regpath_form_alter(&$form, &$form_state, $form_id) {
  // Check to see if we're building this form for a block.
  if (strpos($form_id, 'profile2_regpath_form_block_') === 0) {
    $profile_types = profile2_regpath_get_profiles(NULL, NULL, $form_state['profile_type_id']);
    profile2_regpath_attach_profile_fields($form, $form_state, $form_id, $profile_types);
  }
  elseif ($form_id == 'user_register_form') {
    // Get profile2 profile types from current path.
    $profile_types = _get_profile_types_by_path();
    profile2_regpath_attach_profile_fields($form, $form_state, $form_id, $profile_types);
  }
}

We should find a more robust way that succeeds in managing these situations.

Comments

tcalin’s picture

Here is a quick fix that works for me.
I get the profile based on path taken from form's action (The two lines of code above the last commented line).

function profile2_regpath_form_alter(&$form, &$form_state, $form_id) {
  // Check to see if we're building this form for a block.
  if (strpos($form_id, 'profile2_regpath_form_block_') === 0) {
    $profile_types = profile2_regpath_get_profiles(NULL, NULL, $form_state['profile_type_id']);
    profile2_regpath_attach_profile_fields($form, $form_state, $form_id, $profile_types);
  }
  elseif ($form_id == 'user_register_form') {
    // Get profile2 profile types from current path.
    $path = end(explode('/', str_replace('/register', '', $form['#action'])));
    $profile_types = profile2_regpath_get_profiles($path);
//    $profile_types = _get_profile_types_by_path();
    profile2_regpath_attach_profile_fields($form, $form_state, $form_id, $profile_types);
  }
}
grasmash’s picture

Thanks for noticing this.

I've made the change that you requested to the dev versions. Additionally, I've used the same method in profile2_regpath_attach_profile_fields(), removing the need for _get_profile_types_by_path() altogether.

I like this method because it actually reduces the number of database queries. I can't see any issues with it at the moment, but I'm doing to leave it in dev for a bit -- dealing with AJAX requests in combination with various path-generation methods has really been the main challenge with this module.

grasmash’s picture

Status: Active » Fixed

Going to change this to fixed. Try out dev and let me know if you have any problems.

tcalin’s picture

It works!
No problems until now.
Thanks for pushing this to the dev!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pritam-osl’s picture

waaaw...It saved my time