0

In the process of registering a user I need to replace the username by email, for this I have created a plugin that hooks to the onUserBeforeSave event where I try to replace the username in the following way

<?php

defined( '_JEXEC' ) or die;

class plgUserOnusersignon extends JPlugin
{
    protected $app;

    public function onUserBeforeSave($oldUser, $isNew, $newUser)
    {
        $newUser['username'] = $newUser['email']; // replace username by email

        // other logic goes here

        return true;
    }
}

Debugging, I can identify that the username value is replaced by email, but then by continuing the process and delegating to libraries/src/User/User.php and calling the save method the username value remains the one that the user wrote

How to modify the value written by a user in the process of registering a user? In my case how can I replace the username with the email in the process of registering a user?

Update 1

I thought that in order to solve, I could delegate this task to javascript, capturing what the user writes in the email input and assign that value to the username input. How can I correctly add a javascript script to the registration form view?

Thanks in advance

  • Why are you trying to replace the user name with an email address? If it is so people can sign in with their email address and/or username then there are extensions in the JED that allow you do that already – Irata Dec 18 '19 at 20:24

Your Answer

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

Browse other questions tagged or ask your own question.