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

Ujval Shah’s picture

Drupal - 7:

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

Example: node--blog.tpl.php

astanley86’s picture

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.

larowlan’s picture

Instead of arguments you need the following

   'render element' => 'form'

in your hook_theme

Lee Rowlands

--author="larowlan <larowlan@395439.no-reply.drupal.org>"
astanley86’s picture

Yes this works! Thank you Larowlan.

bryancasler’s picture

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

parisek’s picture

Here is example:

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

nampham’s picture

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.

nampham’s picture

I user 'user_register_form' instead of 'user_register'

shaun873’s picture

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.

carwin’s picture

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

drupalmouse82’s picture

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

SGhosh’s picture

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. :)

carwin’s picture

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!

flefle’s picture

...

subhojit777’s picture

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

Regards,
Subhojit Paul

Ludo.R’s picture

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

  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.

carwin’s picture

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

Seph’s picture

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:


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>

/**
 * 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!

operations’s picture

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.

destinationsound’s picture

Whenever I post print drupal_render_children($form); In the form it pulls all of my original form data, defeating the pourpose.

What do i do to get the actions to complete without pulling the whole form?

cfemocha’s picture

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.

harsh111’s picture

i have done exactly the same thing above but on submit the form i won't get error class on the elements am i doing something wrong ? or missing out anything????//

zuhair_ak’s picture

From tutorial in this link :- https://www.drupal.org/docs/7/theming/overriding-themable-output/customi...

We don't need to pass a variable containing the form content we want rendered in the preprocess function. The variable exists already in the $vars array and can be rendered in the .tpl.php file.

nravens’s picture

This is an old thread but I'm having an issue with this and hoping someone is able to assist.

I've created a user-register-form.tpl.php to override the default user registration page. It displays all the fields I need except for the password fields. I'm using LoginToboggan to allow users to set a password when registering, so in the default user registration page 2 password fields are displayed.

I have the following in my template.php file:

function scholarly_lite_theme() {
$items = array();

$items['user_register_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'scholarly_lite'),
'template' => 'user-register-form',
'preprocess functions' => array(
'scholarly_lite_preprocess_user_register_form'
),
);
return $items;
}

function scholarly_lite_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 my user-register-form.tpl.php

<?php
print render($form['form_build_id']);
print render($form['form_id']);

print render($form['account']['name']);
print render($form['account']['mail']);
print render($form['account']['pass-pass1']);
print render($form['account']['pass-pass2']);

print render($form['field_gender_account']);
print render($form['field_date_of_birth_account']);

print render($form['captcha']);

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

It displays all except password fields. What am I doing wrong?

If I add:

print drupal_render_children($form);

Then it adds the password fields below the Register button which is not idea but then the form works.

Also, I am using the "Auto Assign Role" module with "User Choice" set to allow users to select a second role if relevant to them during registration. I can do without this. When adding render_children as mentioned above, it displays this option below the password fields.

Please can someone assist with how I can get the Password fields displayed without using render_children.

Thanks