0
votes

Drupal 7, I want to load the user profile form into a module page. I have a custom field also that the user can configure, let's call this field "blah". It's a implemented as a dropdown field.

When I load the form using the following code everything is fine apart from the blah field which does not populate its user stored data.

form_load_include($form_state, 'inc', 'user', 'user.pages');
global $user;
$output .= drupal_render((drupal_get_form('user_profile_form', $user)));

Does anyone know how I would get the blah variable/value/user data into this rendered form? It is populated if I go to the standard user profile editing page at http://example.com/user/2/edit.

3

3 Answers

2
votes

You should be able to achieve this using user_load api.

global $user;
$user_fields = user_load($user->uid);
print_r($user_fields);
1
votes

Solved it! I think the very act of posting on Stack Overflow sometimes brings you around to working it out. It was just as simple as $user->field_blah['und'][0]['value'] = 12345;

1
votes

Possible Solutions:- 1)If its a custom field make it belong to user entity bundle and true for user register form while attaching it to user bunble. 2)U can use field_attach_form, 3)form alter