Hello,

I get the following error message preventing the rendering of the user registration page:

Notice: Undefined index: render element in theme() (line 824 of /home/volunteermark/www/www/includes/theme.inc).
    Warning: Missing argument 2 for user_register_form(), called in /home/volunteermark/www/www/sites/all/themes/volunteermark/template.php on line 164 and defined in user_register_form() (line 3643 of /home/volunteermark/www/www/modules/user/user.module).
    Recoverable fatal error: Argument 1 passed to drupal_array_get_nested_value() must be an array, null given, called in /home/volunteermark/www/www/modules/field/field.form.inc on line 450 and defined in drupal_array_get_nested_value() (line 6339 of /home/volunteermark/www/www/includes/common.inc).

Here is what my user-register.tpl.php source code looks like:

<h1>Testing that this is my own user registration form</h1>
<?php print render($form['form_id']); ?>
<?php print render($form['form_build_id']); ?>
<?php
print render ($form['field_firstname']);
print
render ($form['field_lastname']);
print
render ($form['field_dob']);
print
render ($form['name']);
print
render ($form['mail']);
print
render ($form['pass']);
print
render ($form['timezone']);
print
render ($form['form_token']);
print
drupal_render($form['actions']); ?>

<input type="submit" name="op" id="edit-submit" value="Create"  class="form-submit" />

What am I doing wrong? I have been able to successfully do this in Drupal 6 and can't find any documentation for what I would need to do for drupal 7. Thank you for your help!

Andrew

Comments

Drupal - 7:

node--[content-type].tpl.php

Example: node--blog.tpl.php

Well I think it is correctly calling the user-register.tpl.php file because here is what I have in my template.php:

function volunteermark_theme(&$existing, $type, $theme, $path) {
$hooks['user_login'] = array('template' => 'templates/user-login','arguments' => array('form' => NULL));
$hooks['user_profile_form'] = array(
      // Forms always take the form argument.
      'arguments' => array('form' => NULL),
      'template' => 'templates/user-profile-edit',
  );
$hooks['user_register_form'] = array(
'arguments' => array('form' => NULL),
      'template' => 'templates/user-register',
  );
  return $hooks;
}
function volunteermark_preprocess_user_profile_form (&$variables) {
$variables['form'] = drupal_build_form('user_profile_form', user_profile_form(array()));
}
function volunteermark_preprocess_user_register_form (&$variables) {
$variables['form'] = drupal_build_form('user_register_form', user_register_form(array()));
}
function volunteermark_preprocess_user_login(&$variables) {
$variables['form'] = drupal_build_form('user_login', user_login(array()));
}

The user edit page works and the user login page works too. And if I remove the reference to the user register page then the error goes away and I get the standard drupal user registration page.

Instead of arguments you need the following

   'render element' => 'form'

in your hook_theme

Lee Rowlands

--author="larowlan <larowlan@395439.no-reply.drupal.org>"

Yes this works! Thank you Larowlan.

Can you post an example of what you got working, I'm running into this same problem as well.

Here is example:

<?php
function node_theme() {
  return array(
    ...
   
'node_list' => array(
     
'variables' => array('items' => NULL, 'title' => NULL),
    ),
   
'node_search_admin' => array(
     
'render element' => 'form',
    ),
    ...
  );
}
?>

via http://drupal.org/update/modules/6/7#hook_theme_render_changes

This is my code in template.tpl.php:

function mytheme_theme($existing, $type, $theme, $path){
$hooks['user_login']=array(
'render element'=>'form',
'template' =>'templates/user-login',
);
$hooks['user_register']=array(
'render element'=>'form',
'template' =>'templates/user-register',
);
$hooks['user_pass']=array(
'render element'=>'form',
'template' =>'templates/user-pass',
);
return $hooks;
}

'user_login' and 'user_pass' are work. I don't know why 'user_register' doesn't work.
I want to customize the registration form. Thanks for your help.

Nam Pham
email: nampham@mbm.vn
skype: nampham-mbm

I user 'user_register_form' instead of 'user_register'

Nam Pham
email: nampham@mbm.vn
skype: nampham-mbm

Hi,

I have the same error as the original post, ie:

Warning: Missing argument 2 for user_register_form(), called in C:\tools\Sites\mytestsite\sites\all\themes\daniel\template.php on line 248 and defined in user_register_form() (line 3682 of C:\tools\Sites\mytestsite\modules\user\user.module).
Recoverable fatal error: Argument 1 passed to drupal_array_get_nested_value() must be an array, null given, called in C:\tools\Sites\mytestsite\modules\field\field.form.inc on line 473 and defined in drupal_array_get_nested_value() (line 6364 of C:\tools\Sites\mytestsite\includes\common.inc).

My hook function and preprocess method are as below:

function daniel_theme() {
  $items = array();
  $items['user_register_form'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'daniel') . '/templates',
    'template' => 'user-register-form',
    'preprocess functions' => array(
      'daniel_preprocess_user_register_form'
    )
  );
  return $items;
}
function daniel_preprocess_user_register_form(&$variables) {
  $variables['form'] = drupal_build_form('user_register_form', user_register_form(array()));
}

The error occurs in the preprocess method. If I remove that line of code, the page will render correctly. But I can then not access the form fields in my user-register-form.tpl.php:

<div>custom user login block</div>
<?php
print render ($form['field_firstname']);
print
render ($form['field_lastname']);
print
render ($form['field_dob']);
print
render ($form['name']);
print
render ($form['mail']);
print
render ($form['pass']);
print
render ($form['timezone']);
print
render ($form['form_token']);
print
drupal_render($form['actions']); ?>

?>

Please let me know what I'm doing wrong.

EDIT: I made a more comprehensive comment below -- this needs to be deleted but I can't figure out how.

excuse my ignorance, but how do I print 2 or more fields in the same line? for example:
print render ($content['field_lastname']) + print render $content['field_lastname']) in the same row. sorry for my bad English, Greetings from Argentina!
Adrian

Hey Adrian,
you could use these two methods
*for the fields you want to display in one line put- display: inline-block;

*for the fields you want to display in one line put- float:left;
and if some other field unnecessarily appears beside then for that field put clear: left;

I believe this should work. All the best. :)

I used this thread as a base for my own successful theme modifications to User Registration and I thought I'd share in case someone comes along looking for the same things I did.

Firstly, in your theme's template.php:

<?php
function YOURTHEME_theme(&$existing, $type, $theme, $path){
 
$hooks = array();
  
// Make user-register.tpl.php available
 
$hooks['user_register_form'] = array (
    
'render element' => 'form',
    
'path' => drupal_get_path('theme','YOURTHEME'),
    
'template' => 'user-register',
    
'preprocess functions' => array('YOURTHEME_preprocess_user_register_form'),
  );
  return
$hooks;
}
function
YOURTHEME_preprocess_user_register_form(&$vars) {
 
$args = func_get_args();
 
array_shift($args);
 
$form_state['build_info']['args'] = $args;
 
$vars['form'] = drupal_build_form('user_register_form', $form_state['build_info']['args']);
}
?>

-------------------------------------

Hopefully you guys can find this information useful about your user-register.tpl.php

Account fields

Account fields are rendered following the pattern of the two required fields, 'name' and 'mail':

<?php
print render($form['account']['name']);
print
render($form['account']['mail']);
?>

Profile2 Support

To load Profile2 fields into the user registration form manually, use this pattern:

<?php
print render($form['profile_theprofile_name']['field_thefield_name']);
?>

Also, I make use of field group module (here) with Profile2 and noticed that I didn't need to include anything about the field group a Profile2 field is in to render that field.

CAPTCHA

If you use the CAPTCHA module and need to build your own user-register.tpl.php you'll need this to render it:

<?php
 
print render($form['captcha']);
?>

This took me longer than it should of to figure it out.

Submission

Lastly, if you want your form to actually be usable, the following snippet is required to build the form action stuff:

<?php
 
print drupal_render($form['actions']);
  print
drupal_render($form['form_build_id']);
  print
drupal_render($form['form_id']);
?>

Enjoy!

...

Thanks. I was wondering how to separate the fields of account field. This helped me

Regards,
Subhojit Paul
Web Developer @ Innoraft Solutions

For the last part, you should use instead print drupal_render_children($form);

<?php
 
print drupal_render($form['actions']);
  print
drupal_render_children($form);
?>

Drupal will render all elements that have not been rendered yet, inluding $form['form_build_id'] and $form['form_id'].

So if you or a module adds an element (visible or not), it will be automatically rendered.

Thanks, that's great information. If I could update my post I would.

I followed all the code in this thread and I have gotten it so my user--register.tpl.php template is recognized, but none of my fields are showing up. I'm pretty new to this, so I'm not sure where I'm messing up.

Here is what's in my template.php:

<?php
function corolla_theme(&$existing, $type, $theme, $path){
 
$hooks = array();
  
// Make user-register.tpl.php available
 
$hooks['user_register_form'] = array (
    
'render element' => 'form',
    
'path' => drupal_get_path('theme','corolla'),
    
'template' => 'user--register',
    
'preprocess functions' => array('corolla_preprocess_user_register_form'),
  );
  return
$hooks;
}
function
corolla_preprocess_user_register_form(&$vars) {
 
$args = func_get_args();
 
array_shift($args);
 
$form_state['build_info']['args'] = $args;
 
$vars['form'] = drupal_build_form('user_register_form', $form_state['build_info']['args']);
}
?>

And this is what's in my user--register.tpl.php:

<h1>Testing that this is my own user registration form</h1>

<?php
/**
* Prints Profile2 fields.
*/
 
print render($form['profile_main']['field_intro']);
  print
render($form['profile_main']['field_first_name']);
  print
render($form['profile_main']['field_last_name']);
/**
* Prints Registration fields.
*/
 
print render($form['account']['name']);
  print
render($form['account']['mail']);
  print
render($form['account']['conf-mail']);
  print
render($form['account']['pass-pass1']);
  print
render($form['account']['pass-pass2']);
  print
render($form['account']['regcode-code']);
  print
render($form['account']['submit']);
  print
drupal_render($form['actions']);
  print
drupal_render_children($form);
?>

All that's showing up on the page is "Testing that this is my own user registration form"

Any guidance would be greatly appreciated!

Regarding profile2 form elements and in order for them to be available, you have to tick the checkbox Show during user account registration. under your profile type. Otherwise the $form['profile_name'] won't be available.

thank you for your tutorial it was very helpful.
I was wondering what syntax should I use to output any verification error messages to the page. Any help is appreciated.