I am reformatting the standard Drupal User Registration form on a site. Using the drupal_render() function, I am able to post all the fields onto the form without a problem. But, posting all the forms has lead to asking for duplicate information, which I consider bad design. I am using the library module, which requires the user to enter a first name and last name, but I also have that information available in the profile itself. Is there a way that I can do the following:

1. Use the profile module to get first and last name information.
2. Hide the library modules fields.
3. Use the profile module's fields to pass information to the library module fields, so that they are populated when the form is submitted. I'm using Drupal 6, if that isn't already obvious.

Thanks for the help!

zanlus

Comments

duckzland’s picture

you can use the content profile to replace the profile module and define what should be displayed on the registration page

or you can use preprocess function in template.php to sort out the field that you want to display by modifying the $form variable

function your_theme_theme() {
  return array(
    // The form ID.
    'search_block_form' => array(
      // Forms always take the form argument.
      'arguments' => array('form' => NULL),
    ),
    'user_login' => array(
      'template' => 'user-login',
      'arguments' => array('form' => NULL),
    ),
/** Register page related **/
    'user_register' => array(
      'template' => 'user-register',
      'arguments' => array('form' => NULL),
    ),
    'user_pass' => array(
      'template' => 'user-pass',
      'arguments' => array('form' => NULL),
    ),
  );
}

function your_theme_preprocess_user_register(&$vars) {

/** Example of modifying $form **/
/** adding fieldset to login name ,email and password **/
	$vars['form']['login-information'] = array(
		'#type' => 'fieldset',
		'#collapsible' => true,
		'#title' => t('Account Information'),
		'#collapsed' => false,
		'#attributes' => array('class' => 'login-information'),
	);
	$vars['form']['login-information']['name'] = $vars['form']['name'];
	$vars['form']['login-information']['mail'] = $vars['form']['mail'];
	$vars['form']['login-information']['pass'] = $vars['form']['pass'];
	unset($vars['form']['name']);
	unset($vars['form']['mail']);
	unset($vars['form']['pass']);
/** adding collapsible, collapsed and class for avatar picture module **/
	if (module_exists('avatar_selection')) {
		$vars['form']['picture']['#title'] = t('Choose your avatar picture');
		$vars['form']['picture']['#collapsible'] = true;
		$vars['form']['picture']['#collapsed'] = false;
		$vars['form']['picture']['#attributes'] = array('class' => 'avatar-picture');
		unset($vars['form']['picture']['select_avatar']['#title']);
	}
/** adding collapsible , collapsed star and class for term of use module **/
	if (module_exists('terms_of_use')) {
		$vars['form']['terms_of_use']['#collapsible'] = true;
		$vars['form']['terms_of_use']['#collapsed'] = false;
		$vars['form']['terms_of_use']['#attributes'] = array('class' => 'terms-service');
	}

  $vars['rendered'] = drupal_render($vars['form']);
/** print all the $form for debugging **/
  $vars['debug'] = print_r($vars['form'], TRUE);
}

/** create user-register.tpl.php with these lines **/

print t('Join us');

print t('Fill out the form to complete the registration process');

print $rendered;
print $debug; //debugging only

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com

zanlus’s picture

Sorry, I'm afraid that I wasted your time by not giving more information. Let me try to fix that.

Here is the $hooks implementation in template.php using a zen subtheme:

function anisa_theme(&$existing, $type, $theme, $path) {
  $hooks = zen_theme($existing, $type, $theme, $path);
  /* Override the user-registration form */
  $hooks['user_register'] = array(
    'template' => 'user-register',
    'arguments' => array('form' => NULL)
  );
  return $hooks;
}

I suspect that a preprocess function might do what I need, but the way that you have presented doesn't seem to fit. I want to control the display of each field on the page, which has lead me to use drupal_render to display the fields in the user-register.tpl.php file. Here are the fields that I need to present:

<?php print drupal_render($form['Personal Information']['profile_first_name']); ?>
<?php print drupal_render($form['Personal Information']['profile_surname']); ?>

The fields that I want to hide are:

<?php print drupal_render($form['Required Patron Fields']['name_first']); ?>
<?php print drupal_render($form['Required Patron Fields']['name_last']); ?>

Based on your suggestion, I think I could do something like the following to hide the fields that I want to hide:

function anisa_theme_preprocess_user_register($vars,$hooks) {
  $vars['form']['Required Patron Fields']['name_first']['#type'] = t('hidden');
  $vars['form']['Required Patron Fields']['name_last']['#type'] = t('hidden');
  print drupal_render($form['Required Patron Fields']);
}

Then on the user-register.tpl.php, would the following assign the value of the revealed field to the hidden field?

<?php
  $vars['form']['Required Patron Fields']['name_first']['#value'] = $vars['form']['Personal Information']['profile_first_name']['#value'];
  $vars['form']['Required Patron Fields']['name_last']['#value'] = $vars['form']['Personal Information']['profile_surname']['#value'];
  print drupal_render($form['Required Patron Fields']);
?>

I could of course try this, but I'd rather have someone who knows more than I do have a look before trying this approach.

Thanks for all the help!

duckzland’s picture

I'm not a zen theme master, I usually build theme from scratch so not too sure about the proper way to do this in zen language :)

after a quick glance :

  $vars['form']['Required Patron Fields']['name_first']['#type'] = t('hidden');
  $vars['form']['Required Patron Fields']['name_last']['#type'] = t('hidden');

// is supposed to be
  $vars['form']['Required Patron Fields']['name_first']['#type'] = 'hidden';
  $vars['form']['Required Patron Fields']['name_last']['#type'] = 'hidden';

// to remove (not hide per say)
  unset($vars['form']['Required Patron Fields']['name_first']);
  unset($vars['form']['Required Patron Fields']['name_last']);

// this may cause double printing if the "personal information" is not unset before rendering
  $vars['form']['Required Patron Fields']['name_first']['#value'] = $vars['form']['Personal Information']['profile_first_name']['#value'];
  $vars['form']['Required Patron Fields']['name_last']['#value'] = $vars['form']['Personal Information']['profile_surname']['#value'];

This approach will failed if zen doesnt have $vars available, so best if you consult with zen documentation for proper way to do this.

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com