3

I need to split the user account edit form that shows up on one page to multiple pages. That means I want to separate change password fields, two custom fields i created - field_first_name and field_last_name and so on. For moving the password fields to new block I used the solution provided in this link How can I display a change password form on its own? and it works great.

I am trying to use the same code except make some minor changes for modifying the custom fields (first name and last name). The only difference is, I need to pre-populate these fields with the values from the current logged in users information.

// Get the currently logged in user object.
$form['#account'] = $GLOBALS['user'];

// Textfield for first name.
$form['field_first_name'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
'#size' => 60,
'#default_value' => what should I enter here?
'#required' => TRUE
);

Also if I enter a new value for these fields, it doesnt get updated in the user account. I am using the following code -

/**
* Submit handler for change_name_form().
*/
function change_name_form_submit(&$form, &$form_state) {
// Set up the edit array to names to user_save()
$edit = array(
'field_first_name' => $form_state['values']['field_first_name'],
'field_last_name' => $form_state['values']['field_last_name']
);

// Save the account with the new name.
user_save($form['#account'], $edit);

// Inform the user.
drupal_set_message(t('Your information has been changed.'));
}

What additions / changes do I need to make to the code to get the desired output? Any help is greatly appreciated -

1

I haven't done this in code, but I split the user profile into multiple pages on my site with the Field Group module (as the module's page says, it is only client-side).

There is a screencast about how the multipage features work.

Another option is the Profile 2 module, which will create actual separate paths for different settings.

  • I want to allow non-linear access to the pages containing the form fields - which means the user should not need to click 5 times to reach the last fields on the form, which would be on the 5th page based on the example in the screencast above, so thats not what I have in mind. I want to place the blocks on separate pages with links in the user submenu. So if users want to only change passwords, users can click on any menu link and they will be provided with just change password fields. The link I posted in my question allows me to do that. Now I am looking to place other fields in blocks. – limcagoldspot Jun 19 '12 at 20:14
  • Ok, if you were looking for a module, perhaps Profile 2 is a better fit. See my updated answer. – Patrick Kenny Jun 20 '12 at 1:34
  • Yes. Thats the path I am planning to take. I will post my approach if it succeeds. Thanks for providing the info.. – limcagoldspot Jun 21 '12 at 19:14
  • I appreciate the answer, however I don't see any setting that allows me to separate each profile 2 field to its own edit form. Could you point out how to accomplish this? – Anon Ymous Oct 4 '15 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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