1

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;
        $elements['field_company_name']['#weight']=-48;
        #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['captcha']['captcha_widgets']['#weight']=-50;
        $elements['pass']['#weight']=-47;
        $elements['questions'][0]['question']['#weight']= 45; 

    return $elements; 
}         

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

2 Answers 2

1

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

 $elements['questions']['#weight']=50;
0

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;
}
1
  • this is not working
    – Rashmi
    Commented Aug 1, 2013 at 4:22

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.