How to display a profile form using profile2 module Profile2 is a module that uses entities to create profiles that are separate from the user account.

From within my module, I want to be able to display a form to edit the profile entities. Possibly using drupal_get_form or maybe Profile2's API or any other method.

What is the best way to go about this?
I did something like this recently. Since profile uses fields, this make things pretty simple. For the form you could do something like this:

function my_profile_form($form, &amp;$form_state) {
  global $user;
  if (!isset($form_state['profiles'])) {
    $profile = profile2_load_by_user($user, 'profile_machine_name');
    if (!$profile) {
      $profile = profile_create(array(
        'type' =&gt; 'profile_machine_name',
        'uid' =&gt; $user-&gt;uid
      ));
    }
    $form_state['profiles'][$profile-&gt;type] = $profile;
  }

  // Use field attach form and handle the fields yourself:
  field_attach_form('profile2', $profile, $form, $form_state);
  // Or use profile2 API which is simpler
  profile2_attach_form($form, $form_state);

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Save'),
  );
  return $form;
}


Since all the profile form only is the fields that are attached to the profile, you can simply attach the fields yourself to the form, using Drupal core APIs: 


field_attach_form adds the fields to the form.
field_attach_validate handles validation.
field_attach_submit to handles adding the values to the entity (profile).
Lastly you would need to save the profile entity using profile2_save.


After browsing the profile2 module code, I found that it provides a wrapper function to attach the fields to the form and save the form. This is simpler, but in doing so, you loose a little control. To use this you need to use the profile2_attach_form. Doing this will also handle the validation and saving of data.

To use the above code you should be able to c/p it, rename the form and replace profile_machine_name with the actual machine name of the profile you want to display the form for.