Use profile2 fields in custom form I'm trying to add profile2 fields in my custom form. I have created a path in my custom module in hook_menu() and in page arguments inside array, I have passed my custom_form.

In my custom_form I have returned the following code:

function custom_form($form, &amp;$form_state) {

    global $user;
    module_load_include('inc', 'user', 'user.pages');
    return drupal_get_form('user_profile_form', $user); 
}


When I go to the path I do not see the fields which I had created for a particular profile type through manage fields. Instead it renders the default user-profile-form fields.

Where I'm going wrong? Please suggest any ideas.

Thanks In advance
Solved it with the following code:

function custom_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;
}

profile2_attach_form($form, &amp;$form_state);

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