Programmatically change the weight of a form element I have a user activation/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 security_question_form_user_register_form_alter(&amp;$form, &amp;$form_state) {
  if ($form_id == "create_account_form") {
    $form['#pre_render'][] = 'security_question_form_alter_weight';
  }
}

function security_question_form_alter_weight($elements) {
  $elements['questions']['#weight']= -47; 
  return $elements; 
}


It's not working. Can any one have any solution?
You can do this directly inside hook_form_alter, like this:

function security_question_form_user_register_form_alter(&amp;$form, &amp;$form_state) {
  $form['questions']['#weight'] = -47;
}


Then there is no need to create a custom function to do it.

Another thing, you can't implement hook_form_FORM_ID_alter and then use $form_id inside that. You must implement either hook_form_alter, and check if the form id is the one you want, or implement hook_form_FORM_ID_alter and write the form id in the function name.