I have a registration form with different attribute like

Captcha and security questions which are coming from different modules.

I want to change the display order of form elements.

and i am using this code in my custom module

function tenantwallet_form_user_register_form_alter(&$form, &$form_state){
    $form['#pre_render'][] = 'tenantwallet_form_alter_weight';

function tenantwallet_form_alter_weight($elements){

    $elements['field_first_name']['#weight'] = -50;
        $elements['field_last_name']['#weight']= -49;
        #field_company_number, field_secondary_number, field_mobile_or_landline,field_gst_number, field_share_my_info, field_company_logo,field_facebook_id, field_mobile_conformation_code,field_date_of_birth,, field_gender, field_id_proof,field_secondary_id_proof, field_mobile_number,field_promo_emails_notifications,field_sugar_id, captcha, 
        $elements['questions'][0]['question']['#weight']= 45; 

    return $elements; 

But this is not working. Can anybody tell me how to solve this. Thanks


it seems there are different scope in your form . Like question and captcha are in different scope. Try to give weight for each scope too. Then it will work for you. Like


I don't have the possibility to test now, but you should be able to do that directly in the hook_form_FORM_ID_alter() like:

function YOURModule_form_FORM_ID_alter(&$form, &$form_state) {
  $form['elements']['field_name']['#weight'] = 10;
  • this is not working – Rashmi Aug 1 '13 at 4:22

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.