1. mr412
  2. General
  3. Thursday, September 20 2018, 12:04 PM
Hi,
I have disabled login with username. So the username will be created from firstname+"-"+lastname. How can I set the username from a custom field? =)
Accepted Answer
admin Accepted Answer
Admin
Hi,
sorry but this is not possible natively, you need to create a plugin that change the username from DB.
- Download, Install and Enable Skeleton Plugin (you will find it at http://docs.easy-profile.com/index.php/article/triggers)
- Open file /plugins/jsn/skeleton/skeleton.php
- remove samples functions: triggerFieldAvatarUpdate, triggerProfileUpdate
- add function like this:
public function triggerProfileUpdate($user,&$data,$changed,$isNew){ 

$user_id = $user->id;
$new_username = $data['field1']; // Replace field1 with the alias of your custom field

$query = 'UPDATE #__users SET username = ' . $db->quote($new_username) . ' WHERE id = ' . $user_id;

$db = JFactory::getDbo();
$db->setQuery($query);
$db->execute();
}



NOTE: This code is not tested and not supported, this is only for example purpose. You need to have a minimum of PHP knowledges
  1. more than a month ago
  2. General
  3. # Permalink


There are no replies made for this post yet.
However, you are not allowed to reply to this post.