0

I am trying to show the profile2 fields in my user edit page, but I can't figure out how for the life of me. I read that they should autmomatically show up but it's not happening..

I have added the following in my template.php:

function mytheme_theme($existing, $type, $theme, $path){

        $hooks['user_profile_form']    = array(
        'render element'       => 'form',
        'template'             => 'user-profile-form',
        'path'                 => drupal_get_path('theme','mytheme').'/templates');

    return $hooks;
}


function mytheme_preprocess_user_profile_form(&$variables) {
    global $user;
    $variables['form'] = drupal_render($variables['form']['account']);
    //???
    $profile2 = mytheme_profile_form();
}


function mytheme_form_user_profile_form_alter(&$form, &$form_state){
    global $user;
    $mainprofile = profile2_load_by_user($user->uid, 'main');
    $profile = profile2_load_by_user($user->uid, 'basic_information');

    //Example field
    $form['profile_basic_information']['field_field_1']['und']['#id'] = 'school-district';
    $form['profile_basic_information']['field_field_1']['und']['#attributes']['data-placeholder'] = "Choose your Field1";
    $form['profile_basic_information']['field_field_1']['und']['#attributes']['class'] = "input-xlarge";
    $form['profile_basic_information']['field_field_1']['und']['#default_value'] = !empty($profile) && isset($profile->field_field_1['und']) ? $profile->field_field_1['und'][0]['value'] : '';

}

function mytheme_form_user_profile_form_submit(&$form, &$form_state){
    //TODO
}

I also have user-profile-form.tpl which right now consists just of echo $form;

But the fields I am adding to the form are not being added.. I'm not sure that the form_alter is affecting the output (it is running, though).

4
  • 1
    Profile2 fields for which users have edit permission should definitely show up without you having to write any code. Try switching to a different theme temporarily to see if one of your templates is interfering. Commented Jan 23, 2013 at 23:43
  • it's a fully customized theme built from scratch so it may be missing some important variables etc.. do you know what variables should be in there?
    – Damon
    Commented Jan 24, 2013 at 14:54
  • No, I can't give you a list here. You should check one of the popular base themes (Zen) as a reference. Commented Jan 24, 2013 at 15:04
  • i was looking at Bartik/core, and got head, styles, scripts, page-top, page-bottom.. still no dice. it does show up in Bartik tho hm. if i load edit/user/basic_information i just get a blank page in my theme so definitely missing something
    – Damon
    Commented Jan 24, 2013 at 15:40

2 Answers 2

2

I do not think it is an issue regarding with your theme. I have also built a theme from scratch but its showing perfectly up there. You need to change the display settings while you edit your profile type. SO under profile type edit you would find options such as Manage fields, Display fields etc. Under Display fields there would be three tabs just below them...Default, User Account, and Profile Page. By default, the fields which are not required are hidden, you need to change them and then they should show upenter image description here

3
  • This has the profile fields on separate tabs though. It appears the person posting the question wants the fields to display on the main user account edit tab, not in separate tabs.
    – rooby
    Commented Apr 21, 2013 at 1:59
  • I have the same question,how to make the profile fields appear on the user edit page i.e. one page.How did you solve that?
    – Dion
    Commented Oct 12, 2013 at 20:00
  • When installing the panopoly distribution, it works! Profile fields are inside the regular user edit form. But what is the setup need to create that magic?
    – Druvision
    Commented Oct 16, 2013 at 2:13
2

You could try the Account Profile module:

Merges Profile2 forms into user account form.

Profile2 by default creates an additional tab for each new profile assigned to a user. Alternatively the submodule "Profile2 pages" provides a separated pages for viewing and editing profiles.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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