Usually you see that the behavior in node forms when CCK is activated. This is because CCK redefines the weight for the default fields and CCK with a custom ordering system by going to Content Management โ Content Types โ [Content Type] โ Field Management.
Of course, if you disable CCK (maybe not an option), your #weight values โโwill be respected.
It should be noted that although the Forms API allows decimal places for #weight , it is good practice to use integers.
Edit
If you want to work within the limits provided by CCK, in the user module you will need to implement the #pre_render handler, which will change the weight of the form elements after the CCK changes them:
function mymodule_form_alter(&$form, &$form_state, $form_id) { $form['#pre_render'][] = 'mymodule_form_alter_weight'; } function mymodule_form_alter_weight($elements) { $elements['cid']['#weight'] = 0.003; $elements['subject']['#weight'] = 0.004; return $elements; }
The problem is that you donโt know what CCK weight values โโwere used for other form elements, therefore, while you order cid in front of the object, both fields can be displayed in the middle of all other fields on the page and not in the initial position.
CCK puts you in a corner when it comes to weight. The right way for Drupal / CCK to process orders for forms is to respect the choices made by the administrator in Content Management โ Content Types โ [Content Type] โ Field Management.
If you have a custom form element, you can tell CCK so that it appears in the "Field Management" section by implementing hook_content_extra_fields() . Continuing the code above:
function mymodule_content_extra_fields() { $extras['mymodule'] = array( // Name of field 'label' => t('Mymodule'), 'description' => t('Mymodule field'), 'weight' => 10, // The default weight, can be overriden on Manage Fields ); return $extras; }
user113292
source share