This module was simple to plugin and did the trick! But when I enabled Profiles and added fields to the registration form, the username field came back. After looking at the module, the email_registration assumed that the field was on the root level of the form.
Therefore, I added a function that looks for the form in the field. If it doesn't find the field, it traverses into the form's fieldsets.
function email_registration_inject(&$form, $fieldname, $attrib = array()) {
// make sure we have something to inject before we recursively search for this field
if (! count($attrib)) return;
// check for our field in the form, this may be the root form array, a fieldset
if (isset($form[$fieldname])) {
$form[$fieldname] = array_merge($form[$fieldname], $attrib);
return true;
}
// so far we haven't found the field we are looking for, check for fieldsets and traverse them as well
else {
foreach (array_keys($form) AS $field) {
if (! strpos($field, '#') && isset($form[$field]['#type']) && $form[$field]['#type'] == 'fieldset') {
if (email_registration_inject($form[$field], $fieldname, $attrib))
return true;
}
}
}
return false;
}
Attached is the entire module file with this implemented. It supports all the forms, whether they use have fieldsets or not.
Comments
Comment #1
lee20 commentedGeez, I forgot to check the issue list before posting! So this is a duplicate.
But I'll argue, a more surefire way to solve the problem as it resolves the problem globally and not just for the profile issue. I am not aware of any other modules that may restructure the registration form, but this will prevent the problem in either case.
Comment #2
lee20 commentedAttached is an actually patch file instead of the entire module file.
Comment #3
Christopher Herberte commentedapplied patch from http://drupal.org/node/183820
Comment #4
Phillip Mc commentedgreat module.
Just adding a note to say there's a similar conflict withe the regcode.module.
this fixes it after you have applied the profile module patch above
In other words, delete the
if (module_exists('profile')){and replace withif ((module_exists('profile')) || (module_exists('regcode'))) {