I need to do theming of user registration form

I m doing in this way

Module file

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

Template file

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

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

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

<?php echo $rendered; ?> 

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


2 Answers 2


You can skip your preprocess function and render directly in your template file like this:

<?php print drupal_render($form['user_register']['username']); ?>
<?php print drupal_render($form['user_register']['firstname']); ?>
<?php print drupal_render($form['user_register']['email']); ?>
<?php print drupal_render($form['user_register']['lastname']); ?>
<?php print drupal_render($form['user_register']['password']); ?>

Wrap these lines of code inside HTML if you want to. Use <?php print drupal_render_children($form); ?> to render automatically the rest of the fields you haven't rendered yet.


An example:

<div id="username">
  <?php print drupal_render($form['user_register']['username']); ?>
<div id="firstname">
  <?php print drupal_render($form['user_register']['firstname']); ?>
  • what about form submissions, how it will work then
    – Hitu
    Oct 10, 2014 at 8:05
  • Don't modify anything of what you've done. Just skip your mytheme_preprocess_user_register function and work directly in your user-register.tpl.php file using the syntax I showed you.
    – Djouuuuh
    Oct 10, 2014 at 8:07
  • yes, i did i smae. it is showing all fields
    – Hitu
    Oct 10, 2014 at 8:09
  • You can rearrange them in the order you want, in the HTML tags you want. I'll make an edit in my post to illustrate with an example.
    – Djouuuuh
    Oct 10, 2014 at 8:10
  • yes i did, but why it is displaying all fields. even i didnt add <?php print drupal_render_children($form); ?>
    – Hitu
    Oct 10, 2014 at 8:11

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.

  • Do like this <?php print drupal_render($form['account']['pass']['pass1']);?> Oct 10, 2014 at 7:34
  • Can you pleaase explain it more. I am not able to make it working
    – Hitu
    Oct 10, 2014 at 8:01

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.