1

I want to keep the registration process as simple as possible for my users, like a lot of modern websites do. I want there to be only 3 fields to fill out when creating new accounts: Email, Password, Repeat password.

It seems to me there is no option to remove the mandatory username field from the registration form though, is there any workaround?

1
  • 2
    I've seen hacky techniques like using js to populate the (hidden) Repeat Password field with the Password value. Would you be happy to populate a hidden Username field with the Email field value?
    – mickmackusa
    Sep 11, 2020 at 22:11

2 Answers 2

1

You can achieve this behavior writing a User plugin for joomla and handling the right Events on your needs.

On the event BeforeSave, copy the value of the email into the username

function onUserBeforeSave($oldUser, $isnew, $newUser){
 //email2 is the "repeated email" field
 $newUser["email2"] = $newUser['email1'];
 $oldUser["email2"] = $newUser['email1'];
 //Fill username with email
 $newUser["username"] = $newUser['email1'];
 $oldUser["username"] = $newUser['email1'];
}

On the event that create the subscription form, unset the fields you don't want to show:

function onContentPrepareForm($form, $data){
 //fields to remove (example)
 $form->removeField('email2');
 $form->removeField('spacer');
}

This is just an example, here some Joomla reference to the Events: https://docs.joomla.org/Plugin/Events/User

If in doubt, take a look at the default joomla user plugins

0

I went through the trouble to do this once, and learned that it wasn't worth it. Not that it was too hard - I did it, but it required constant maintenance.

First, when a user registers, you must alter the login form to remove the username field, and when the registration form is submitted, you must INSERT a username, which where it starts getting difficult. The way I did it, was to give it a temporary name and then change the name when the user ID is known.

Then you must override the output of your login modules, the output of the reset password form, the login view of the component, the user account default and edit views....

And when Joomla releases an update that changes any of these things - you get to rewrite the overrides.

Maybe instead, you might consider giving them a "generate username" option....make it fun, or base it on their name, or whatever.

It isn't worth it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.