Problem: Registration form does not submit nodeprofile form when using theme overrides.
I have been trying to theme my registration page but ran into some problems. In my template.php file I used:
function phptemplate_user_register($form) {
return _phptemplate_callback('user-register', array('form' => $form));
}
and then created user-register.tpl.php to theme the page. In the tpl file if I used echo drupal_render($form); then everything looks the same as before the theme override, and everything worked fine. So I got down to work and coded some html. Here is what I came up with:
<?php
drupal_set_title('Sign Up');
/*** Unset any information we do not want to use ***/
unset($form['account']['name']['#description']);
unset($form['account']['pass']['#description']);
unset($form['account']['mail']['#description']);
unset($form['uprofile']['form']['#form']['field_address']);
unset($form['uprofile']['form']['#form']['group_links']);
unset($form['uprofile']['form']['#form']['field_company_1']);
unset($form['uprofile']['form']['#form']['field_contact_phone']);
unset($form['uprofile']['form']['#form']['field_type_of_company']);
$form['uprofile']['form']['#form']['group_height']['field_feet']['key']['#options'][''] = t('Feet');
$form['uprofile']['form']['#form']['group_height']['field_inches']['key']['#options'][''] = t('Inches');
$form['uprofile']['form']['#form']['field_ethnicity']['key']['#options'][''] = t('Ethnicity');
$form['uprofile']['form']['#form']['field_state_0']['key']['#options'][''] = t('State');
$form['uprofile']['form']['#form']['field_gender']['key']['#options'][''] = t('Gender');
$form['submit']['#value'] = t('Continue');
$form['account']['name']['#title'] = '';
$form['account']['mail']['#title'] = '';
$form['account']['pass']['pass1']['#title'] = '';
$form['account']['pass']['pass2']['#title'] = '';
$form['uprofile']['form']['#form']['field_first_name']['values']['#title'] = '';
$form['uprofile']['form']['#form']['field_last_name']['values']['#title'] = '';
$form['uprofile']['form']['#form']['field_city_0']['values']['#title'] = '';
$form['uprofile']['form']['#form']['field_zip']['0']['value']['#title'] = '';
$form['uprofile']['form']['#form']['field_phone_home']['0']['value']['#title'] = '';
$form['uprofile']['form']['#form']['field_phone_cell']['0']['value']['#title'] = '';
$form['uprofile']['form']['#form']['group_height']['field_inches']['key']['#title'] = '';
$form['uprofile']['form']['#form']['group_height']['field_feet']['key']['#title'] = '';
$form['uprofile']['form']['#form']['field_birthdate']['0']['value']['mday']['#title'] = '';
$form['uprofile']['form']['#form']['field_birthdate']['0']['value']['mon']['#title'] = '';
$form['uprofile']['form']['#form']['field_birthdate']['0']['value']['year']['#title'] = '';
$form['uprofile']['form']['#form']['field_ethnicity']['key']['#title'] = '';
$form['uprofile']['form']['#form']['field_state_0']['key']['#title'] = '';
$form['uprofile']['form']['#form']['field_gender']['key']['#title'] = '';
$form['uprofile']['form']['#form']['group_other']['field_languages']['values']['#title'] = '';
$form['uprofile']['form']['#form']['field_referrer']['0']['user_name']['#title'] = '';
$form['account']['name']['#size'] = 15;
$form['account']['mail']['#size'] = 15;
$form['account']['pass']['pass1']['#size'] = 15;
$form['account']['pass']['pass2']['#size'] = 15;
$form['uprofile']['form']['#form']['field_first_name']['values']['#size'] = 15;
$form['uprofile']['form']['#form']['field_last_name']['values']['#size'] = 15;
$form['uprofile']['form']['#form']['field_city_0']['values']['#size'] = 15;
$form['uprofile']['form']['#form']['field_zip']['0']['value']['#size'] = 15;
$form['uprofile']['form']['#form']['field_phone_home']['0']['value']['#size'] = 15;
$form['uprofile']['form']['#form']['field_phone_cell']['0']['value']['#size'] = 15;
?>
<div class="reg-status">
<div>
<div class="reg-status-blurb">Registration Status Bar</div>
<div class="reg-status-step">Step 1 of 4</div>
<div class="clear-fix"></div>
</div>
<div class="reg-status-block"><span>Profile</span></div>
<div class="reg-status-block"><span>Images</span></div>
<div class="reg-status-block"><span>Subscription</span></div>
<div class="reg-status-block"><span>Finish</span></div>
<div class="clear-fix"></div>
</div>
<div class="clear-fix"></div>
<div id="reg-account-basic">
<div id="reg-account">
<div class="reg-header">
<div class="reg-header-l"></div>
<div class="reg-header-repeat"><span><?php echo t('Account Information'); ?></span></div>
<div class="reg-header-r"></div>
<div class="clear-fix"></div>
</div>
<div id="reg-account-content">
<?php
echo drupal_render($form['account']['name']);
echo drupal_render($form['account']['mail']);
echo drupal_render($form['account']['pass']); ?>
<div target="edit-mail" class="hovertip"><?php echo t('Your email address is not made public and will only be used if you wish to receive a new password or wish to receive news or notifications by email.'); ?></div>
</div>
</div>
<div id="reg-basic">
<div class="reg-header">
<div class="reg-header-l"></div>
<div class="reg-header-repeat"><span><?php echo t('Basic Information'); ?></span></div>
<div class="reg-header-r"></div>
<div class="clear-fix"></div>
</div>
<div id="reg-basic-content">
<div id="reg-basic-content-l">
<?php
echo drupal_render($form['uprofile']['form']['#form']['field_first_name']);
echo drupal_render($form['uprofile']['form']['#form']['field_city_0']);
echo drupal_render($form['uprofile']['form']['#form']['field_state_0']);
echo drupal_render($form['uprofile']['form']['#form']['field_phone_home']);
echo drupal_render($form['uprofile']['form']['#form']['field_ethnicity']);
?>
</div>
<div id="reg-basic-content-r">
<?php
echo drupal_render($form['uprofile']['form']['#form']['field_last_name']);
echo drupal_render($form['uprofile']['form']['#form']['field_zip']);
echo drupal_render($form['uprofile']['form']['#form']['field_phone_cell']);
echo drupal_render($form['uprofile']['form']['#form']['field_gender']);
?>
</div>
<div class="clear-fix"></div>
<div id="reg-basic-content-b">
<div><div id="reg-basic-content-b-birthdate"><?php echo t('Birthdate'); ?></div><div id="reg-basic-content-b-height"><?php echo t('Height'); ?></div></div>
<div class="clear-fix"></div>
<?php
echo drupal_render($form['uprofile']['form']['#form']['field_birthdate']['0']['value']['mday']);
echo drupal_render($form['uprofile']['form']['#form']['field_birthdate']['0']['value']['mon']);
echo drupal_render($form['uprofile']['form']['#form']['field_birthdate']['0']['value']['year']);
?><?php
echo drupal_render($form['uprofile']['form']['#form']['group_height']['field_feet']);
echo drupal_render($form['uprofile']['form']['#form']['group_height']['field_inches']);
?>
</div>
<div class="clear-fix"></div>
<div target="edit-mail" class="hovertip">Your email address is not made public and will only be used if you wish to receive a new password or wish to receive news or notifications by email.</div>
</div>
</div>
<div class="clear-fix"></div>
</div>
<div id="reg-about">
<div class="reg-header">
<div class="reg-header-l"></div>
<div class="reg-header-repeat"><span><?php echo t('About Me'); ?></span></div>
<div class="reg-header-r"></div>
<div class="clear-fix"></div>
</div>
<div id="reg-about-content">
<?php echo drupal_render($form['uprofile']['form']['#form']['group_other']['field_languages']); ?>
<div id="reg-field-manager">
<?php echo drupal_render($form['uprofile']['form']['#form']['group_other']['field_manager']); ?>
<div class="clear-fix"></div>
</div>
<div id="reg-field-manager-experience">
<?php echo drupal_render($form['uprofile']['form']['#form']['group_other']['field_manger_experience']); ?>
</div>
<div id="reg-field-transportation">
<?php echo drupal_render($form['uprofile']['form']['#form']['group_other']['field_transportation']); ?>
<div class="clear-fix"></div>
</div>
<?php
echo drupal_render($form['uprofile']['form']['#form']['group_other']['field_license']);
echo drupal_render($form['uprofile']['form']['#form']['group_other']['field_about_me']);
?>
</div>
</div>
<div id="reg-experience">
<div class="reg-header">
<div class="reg-header-l"></div>
<div class="reg-header-repeat"><span><?php echo t('Experience'); ?></span></div>
<div class="reg-header-r"></div>
<div class="clear-fix"></div>
</div>
<div id="reg-experience-content">
<?php
echo drupal_render($form['uprofile']['form']['#form']['group_other']['field_mobile_market']);
echo drupal_render($form['uprofile']['form']['#form']['group_other']['field_resume']);
echo drupal_render($form['uprofile']['form']['#form']['group_other']['field_options']);
?>
</div>
</div>
<div id="reg-other">
<div class="reg-header">
<div class="reg-header-l"></div>
<div class="reg-header-repeat"><span><?php echo t('Other'); ?></span></div>
<div class="reg-header-r"></div>
<div class="clear-fix"></div>
</div>
<div id="reg-other-content">
<?php
echo drupal_render($form['uprofile']['form']['#form']['field_referrer']);
?>
</div>
</div>
<?php
echo drupal_render($form);
?>and with a touch of CSS the page looks like the image attached.
Now the problem started. When you submit the form it would not submit the nodeprofile with the user_register form. After further investigation, I came up with the following solution: merge the form data and set the submit handlers.
function nodeprofile_get_register_form() {
$form = array();
foreach (nodeprofile_get_types('names') as $type => $type_name) {
if (nodeprofile_get_settings('register', $type)) {
// If a role has been selected for registration.
if (module_exists('rolesignup') && isset($_SESSION['role'])) {
// Find roles relevant to Role Signup that have settings for the current type.
if ($register_roles = nodeprofile_get_settings('register_roles', $type)) {
$user_roles = user_roles(TRUE, 'register for role');
if (!isset($user_roles[$_SESSION['role']]) || !isset($register_roles[$_SESSION['role']])) {
continue; // Do not show the current type.
}
}
}
$form[$type] = array(
'#type' => 'fieldset',
'#title' => check_plain($type_name),
'#collapsible' => TRUE,
'#weight' => nodeprofile_get_settings('weight', $type),
);
$node = (object)array('uid' => 0, 'name' => '', 'type' => $type);
$form[$type]['form'] = array(
'#type' => 'subform',
'#id' => $type. '_node_form',
'#arguments' => array($node),
'#subform_after_build' => array('nodeprofile_integration_adapt_node_form'),
//
// You must combine the form data else it will not submit the data correctly
//
'#data_separation' => FALSE,
);
//
// Now we need to reset the user_register_submit submit handler because it will unset itself when you add another handler
// Then add subform_element_sumit so the nodeprofile form gets submitted correctly too
//
$form['#submit']['user_register_submit'] = array();
$form['#submit']['subform_element_submit'] = array();
}
}
if (!empty($form)) {
$form['#attributes']['enctype'] = 'multipart/form-data';
return $form;
}
}
With these changes everything seems to work now!
| Comment | File | Size | Author |
|---|---|---|---|
| register_profile.png | 231.02 KB | JStarcher |
Comments
Comment #1
rcross commentedI'm not sure if this is related or not - but I'm just trying to do something simple (i think). It appears that when i adjust the weighting of the cck fields for the node, that it is not reflected in the registration page. It is reflected in the edit and regular create pages, but not the registration form (which is the most important). This seems like a bug, and since i'm not trying to do any custom theming i'm hoping to avoid playing with the suggested code. Any suggestions?
Comment #2
JStarcher commentedI would probably submit a separate issue for that, it does seem like a bug which should be individually addressed.
Comment #3
FrontBurner commentedI am surprised this isn't a frequent request. I have been pulling my hair out trying to figure out how to theme the registration page with no luck at all. Sucks butts.
Comment #4
Sam Dark commentedEncountered the same problem today. Spent a day fighting it. Not sure if it's inside uprofile, subform or Druapal.
To reproduce:
template.php
user_register.tpl.php
Comment #5
Sam Dark commentedToday tried to change button value (title) using JS. The same no submit effect. Very strange…
Comment #6
fagoI don't think there is a bug - it's just a bit more difficult than usual.
You can theme the registration form as usual, but the subform needs to be themed on its own. Just the theme the form of the nodeprofile, and it should appear themed on the registration page.