1

I have a User Profile page that loads specific taxonomy terms (associated with a user account and its form, user_profile_form) to filter specific content with. I've tried to implement these forms independent of any user profile form logic, but its troublesome to work around this logic.

This is further compounded by the fact that all this behavior is essentially split across a ctools_wizard form, since this component ties in a multi-page/multi-form process.

Is there a way I can load in these specific fields, inherited from user_profile_form, into a new form and have those changes save within that form, or is there an entirely separate approach to use here?

5
  • are the terms your talking about 'fields' in the user profile ? Commented Dec 5, 2014 at 23:05
  • @user1081275 Yes, they are fields. I should have specified that above Commented Dec 5, 2014 at 23:06
  • then they are available in the $user object. Can you just $user = user_load($uid); in your form, then retrieve the term id from $user->field_term[LANGUAGE_NONE][0]['target_id'] or something ? Commented Dec 5, 2014 at 23:09
  • I can store and retrieve values, but I would need to build a form around them. I am looking to see if there's a way I can insert user_profile_form, which is exposed to any authenticated user, and its attributes to another form. I've tried using a drupal_get_form() call but it fails to load because that id does not exist. Commented Dec 6, 2014 at 1:28
  • you want to load a user_profile_form inside another form just to get the form data ? Commented Dec 6, 2014 at 14:33

1 Answer 1

0

If you want to pass variables to a form you can. See this similar post.

Just add $vars as second argument.

drupal_get_form('new_form', $vars);

and...

function new_form($form, &$form_state, $vars) {

If you are trying to pass the user object to user_profile_form you can do it like so:

global $user;
$form_state = array();
$form_id = 'user_profile_form';
$args = array($user);
$form_state['build_info']['args'] = $args;
form_load_include($form_state, 'inc', 'user', 'user.pages');
print render(drupal_build_form($form_id, $form_state));

If you really want to load the user_profile_form inside another form (?) as suggested in your comment, you can do the snippet above but not render the form, just load it into an a variable and extract vars from it.

$loaded_profile_form_with_user = drupal_build_form($form_id, $form_state);

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.