By John Whelan on Thursday, 26 June 2014
Posted in General Issues
Likes 0
Views 666
Votes 0
I posted about this a couple of weeks ago and after quite a bit of troubleshooting I can confirm that the issue appears as follows:

Context
1) 'name' is set as not required in the profile custom fields
2) 'name' is set to not display during registration
3) 'name' is set as a single name (not first, last)

Result
1) 'name' is not saved as 'username' in database, it is saved as 'Guest'

I think that the reason is that the following code snippet only checks for the 'name' if it is displayed during registration but not required:

public function onRegisterBeforeSave(&$post)
{
if (empty($post['first_name']) && !empty($post['username']) && $this->params->get('username_fallback')) {
$post['first_name'] = $post['username'];
}

return $this->save($post);
}


This piece of code should be modified to also check if the 'name' is not displayed and not required during registration. Is there an easy fix? I could use the code on my site.

- JW
Hi John,

I actually can't think of any unintended consequences, hence I am considering to include this in the next release.

(We'll never know until we include and release it anyway LOL)

I'll go ahead and add this then.
·
Thursday, 26 June 2014 15:27
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

Unfortunately for this case, if the name field is not displayed during registration, Joomla defaults it back to Guest.

And also there is no direct (or at least clean code) way to check if name is displayed or not from another field. Each fields acts on its own actually.

Alos, Did you set the username field config of Username Fallback to Yes?
·
Thursday, 26 June 2014 10:35
·
0 Likes
·
0 Votes
·
0 Comments
·
Jason,

There should be a HIDE option. this is what i would have needed in my Auto Add User, instead I have just say appear but didn't output any information.... which was my counter to have it hidding but still working in registering.

Alex
·
Thursday, 26 June 2014 10:38
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

The "HIDE" option is under the "view" tab of the field configuration.
·
Thursday, 26 June 2014 10:41
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks Jason.

Understanding that each field acts on its own is there a way for me to force the 'name' field to save as the username from another field that does appear during registration - say 'username'? Obviously this is something I'd need to keep track of when I upgrade ES.
·
Thursday, 26 June 2014 11:43
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

You can try adding this in the joomla_username/joomla_username.php


public function onRegisterBeforeSave(&$post)
{
if (!empty($post['username']) && empty($post['first_name']) && empty($post['name'])) {
// Assign directly to name because Joomla is reading name instead
// We also check for first_name because first_name is unique to EasySocial and this is to ensure that the field is either empty or not loaded
$post['name'] = $post['username'];
}
}

·
Thursday, 26 June 2014 12:14
·
0 Likes
·
0 Votes
·
0 Comments
·
That works very nicely indeed. I added the code to the end of the joomla_username/joomla_username.php

Would I be correct in assuming that I will need to keep track of this particular modification as it will get overwritten with any ES updates?
·
Thursday, 26 June 2014 13:28
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

Hmm I am actually considering putting this in the core codes. What do you think John?
·
Thursday, 26 June 2014 14:46
·
0 Likes
·
0 Votes
·
0 Comments
·
From my point of view it is a useful piece of code because it means that there will always be a username in place of the Joomla name if the site admin chooses not to not to require and not to display the name during registration. It's like a default option that can be overridden by other settings.

Are there any unintended consequences it might have?
·
Thursday, 26 June 2014 15:24
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks Jason!
·
Thursday, 26 June 2014 15:37
·
0 Likes
·
0 Votes
·
0 Comments
·
No problem
·
Thursday, 26 June 2014 15:52
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post