Comments

adwuk’s picture

I have done this by simply editing email_registration.module and modifying the function email_registration_form_user_register_form_alter.

change

$form['account']['name']['#type'] = 'hidden';
$form['account']['name']['#value'] = 'email_registration_' . user_password();

to

//$form['account']['name']['#type'] = 'hidden';
//$form['account']['name']['#value'] = 'email_registration_' . user_password();
$form['account']['name']['#title'] = t('Your name');

This will ask the user to enter their user name on the registration form, but for password reset, login etc the email address is used. It helps us as we approve some members to have increased access to our website if they are known club members.

I think that it would be worthwhile adding this as a configuration option, and once I figure that part out, I will submit a patch.

user654’s picture

.

greggles’s picture

I could swear this was already possible just by entering your name into the email field. If you change the label on the field that should be good enough. The README.txt of the module explains how to change the label in your settings.php file.

adwuk’s picture

The point, for me at least, is to have both the email and user name field visible for registration purposes. I don't need it for login or password reset though. If there is a better way to progress then no issues - this request sat with no progress for 9 months, so I figured there wasn't.

greggles’s picture

I see. Well, that seems like it could be an optional feature. Especially if you include tests for it :)

adwuk’s picture

So here are my changes. Don't know how to build in tests, but maybe it will serve as the basis for someone to improve.

System Lord’s picture

This is a much needed change for my use. I assume this patch will work for 7.1.2 as well? Perhaps manually?

System Lord’s picture

Seems to work fine on 7.1.2. I patched it manually.

Thanks for this!

System Lord’s picture

I did change t('Your name') to 'Display name' to keep it consistent with the function email_registration_form_user_profile_form_alter

henryhu’s picture

Thanks adwuk, patch is working for me.

knalstaaf’s picture

Version: 7.x-1.1 » 7.x-1.x-dev

I tried this on a 7.x-1.3 and the patch doesn't seem to do the job anymore.

Don't want to push this issue to a philosophical discussion but shouldn't this be an option (configurable by admin) by default?

Interesting D8 discussion in that perspective: #111317: Allow users to login using either their username OR their e-mail address

sadashiv’s picture

Status: Active » Needs review
StatusFileSize
new2.39 KB

Hi,

I modified the patch provided previously, I guess we don't need to create a new menu just for one configuration so added this configuration under admin/config/people/accounts

Thanks,
Sadashiv.

weri’s picture

Status: Needs review » Reviewed & tested by the community

I reviewed and tested the patch #12. It woks as expected and I hope this get committed in the next release.

The last submitted patch, 6: Optional-username-on-user-registration-form.patch, failed testing.

Chetna_Negi’s picture

#12 worked beautifully, thanks @sadashiv

ronino’s picture

I like patch #12, but I'd expect the username field to be optional, at least optionally ;-). Otherwise checking the checkbox literally turns off the functionality of this module for the registration form: to register with an email address only while generating a random username.

You can achieve this with extra validation and submit handlers:

function MODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  // Make the username optional.
  $form['account']['name']['#required'] = FALSE;

  // Register validate and submit handlers to allow username generation by the
  // email_registration module.
  array_unshift($form['#validate'], 'MODULE_register_form_validate');
  array_unshift($form['#submit'], 'MODULE_register_form_submit');
}

function MODULE_register_form_validate($form, &$form_state) {
  // If no username is given, remove the field from the submitted values so
  // user_account_form_validate() ignores it and email_registration can jump in
  // to create a random one.
  if (trim($form_state['values']['name']) == '') {
    unset($form_state['values']['name']);
  }
}

function MODULE_register_form_submit($form, &$form_state) {
  // If the username field doesn't exist, it has been removed in the validation
  // handler, so set a value the email_registration module would have set which
  // makes it create a random one.
  if (!isset($form_state['values']['name'])) {
    $form_state['values']['name'] = 'email_registration_' . user_password();
  }
}

What do you think?

joekers’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Assigned: Unassigned » joekers
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.83 KB

Here's a patch for 8.x-1.x.

dimilias’s picture

Here's a patch for 8.x-1.x.

This should move to a new issue. The whole issue is set for 7.x and now even your patch appears for 7.x :/

dimilias’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
joekers’s picture

Ah sorry I thought I'd just post a patch in this issue as it's the same for D8 - will create a new one now and post it there instead.

drupalfan2’s picture

Is this patch still necessary for latest Drupal 7 version?

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This issue for d7, d8 one is #2927109: [D8] Allow username on the registration form

this functionality is critical so must be covered with test (could be same as for d8)

andypost’s picture

ronino’s picture

StatusFileSize
new2.53 KB

Updated patch #12 to work with the latest version.

bluegeek9’s picture

Status: Needs work » Closed (outdated)
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:

Drupal 7 is End of Life. We recommend upgrading to a supported version of Drupal.