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

lee20’s picture

Geez, 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.

lee20’s picture

StatusFileSize
new2.7 KB

Attached is an actually patch file instead of the entire module file.

Christopher Herberte’s picture

Status: Needs review » Closed (duplicate)
Phillip Mc’s picture

great 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

function email_registration_form_alter($form_id, &$form) {
  switch ($form_id) {
    case 'user_register':
-      if (module_exists('profile')){
+     if ((module_exists('profile')) || (module_exists('regcode'))) {

In other words, delete the if (module_exists('profile')){ and replace with if ((module_exists('profile')) || (module_exists('regcode'))) {