Is it possible to set the order of core fields against custom fields added on user profile page? I want to bring the status field to the bottom of the list. I'm trying the code below but without succes:

function MY_MODULE_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
  $form['status']['#weight'] = 100;
}

I want something in the following order for example:

  • Username (core)
  • Password (core)
  • Custom field 1
  • Custom field 2
  • Status (core)

Thanks in advance

You can just try and set the weight as follows

$form['status']['#weight'] = field_info_max_weight('user', 'user', 'form') + 10;

Have not tried it but I am pretty sure it will work. This will make sure the status will always be the last field.

Also it should be $form['account']['status']['#weight']

  • Awesome, never even heard of that function before but it's very heplful – Clive Sep 20 '12 at 16:44
  • Ya I came across it from the fields ui module when I was working on a project which created dynamic fields and I was looking for something like that. There is even a hook for that function. – junedkazi Sep 20 '12 at 16:48
  • Yeah so it does, thanks; I'd up-vote again if I could :) – Clive Sep 20 '12 at 16:52
  • Ah i see that the status field is inside the account array. Actually what I intend to do is pull out this status field and set the weight of it according to the other custom fields one level up – undersound Sep 22 '12 at 12:24

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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