Drupal - user registration form- theming I need to do theming of user registration form  

I m doing in this way 

Module file 

  function mymodule_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {
      $form['#theme'] = 'user_register';
    }


Template file 

function mytheme_theme($existing, $type, $theme, $path){
  return array(
    'user_register' =&gt; array(
      'render element' =&gt; 'form',
      'template' =&gt; 'templates/user-register',
    ),
  );
}

function mytheme_preprocess_user_register(&amp;$variables) {
  $variables['rendered'] = drupal_render_children($variables['form']);
}


And then I added user-register.tpl.php with my desired markup, a

&lt;?php echo $rendered; ?&gt; 


Which is working fine . Now problem is that i need to rearrnage order of all fileds 

Currently i have following  

username, email and password, firstname , last name

I need sequence like username , firstname, email, lastname, password 

can anybody tell me how to do this

Thanks
Look at poll module for a good example of this.

You can simply (with item being something in your form);

$form = $variables['form'];
$variables['item'] = drupal_render($form['item']);
$variables['rendered'] = drupal_render_children($form);


However there are other ways of achieving this and keeping the rearranging within the UI (/admin/config/people/accounts/fields etc) by using hook_field_extra_fields - poll module does this as well I've noticed.  It can be used for adding existing base fields which don't otherwise show in the Manage Display UI (like node author, created, updated times, etc) - here's an example for user picture.