By Jordan Weinstein on Monday, 06 February 2017
Posted in General Issues
Likes 0
Views 368
Votes 0
Hello,

I am using a contact form where I wold like to insert the logged in user's first name and last name for the same fields in the contact form.

I can insert code like this in to the field's default value:


$user = JFactory::getUser();
return $user->get('email');


Is there something similar I could use to get the ES First Name and Last Name for those two different fields?

Please note, I have two ES profiles created and Name (first name and last name) appears in both profiles, if this matters

Thanks for considering,

Jordan
This would seem to work better with this type of query:


$db = JFactory::getDBO();
$db->setQuery("SELECT `name` FROM `#_users` WHERE `id` = 62");
$result = $db->loadResult();
return $result;


But I obviously need to tailor for EasySocial so I can retrieve the First Name and Last Name (using 1 query for each I suppose)
·
Monday, 06 February 2017 01:10
·
0 Likes
·
0 Votes
·
0 Comments
·
If you would like to retrieve Easysocial user fullname field data, you can try following method to retrieve those data from the current logged in user :


$id = JFactory::getUser()->id;
// current user profile id
$my = ES::user($id);
// this JOOMLA_FULLNAME unique name getting from your profile type, refer on my following screenshot
$value = $my->getFieldValue('JOOMLA_FULLNAME');
echo $value->first . ' ' . $value->last;exit;


screenshot : http://take.ms/ex5HF
·
Monday, 06 February 2017 12:57
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks Arlex,

However, if I want to separate it in to First Name only for example, I tried:


$id = JFactory::getUser()->id;
// current user profile id
$my = ES::user($id);
// this JOOMLA_FULLNAME unique name getting from your profile type, refer on my following screenshot
$value = $my->getFieldValue('JOOMLA_FULLNAME');
echo $value->first;


And yet it still showed the full name. In the EasySocial user info for that user, the name is indeed entered with a first and last:

http://d.brbns.com/JF76

If I echo only 'last' then nothing appears. So it seems the full name is stored as 'first' but in my screenshot you can see I have values for first and last name.

Any ideas here:

Jordan
·
Monday, 06 February 2017 20:03
·
0 Likes
·
0 Votes
·
0 Comments
·
It seems like that is bug, can you try download my attached file and replace into this file location and see how it goes?

JoomlaFolder/media/com_easysocial/apps/fields/user/joomla_fullname/joomla_fullname.php

By the way, I will consult with our developer regarding this.

Note : Remember backup your original file before you replace the file.
·
Tuesday, 07 February 2017 01:28
·
0 Likes
·
0 Votes
·
0 Comments
·
Yes, that did it

I had also done the same using the following, but both work now:


$db = JFactory::getDBO();
$id = JFactory::getUser()->id;
// current user profile id
$my = ES::user($id);
$db->setQuery("SELECT data FROM MYDATABASE_social_fields_data WHERE datakey = 'last' AND uid = '$id'");
$result = $db->loadResult();
if ($id > 0) {
return $result; }


Hopefully your modified file makes it in to the component permanently.

Jordan
·
Tuesday, 07 February 2017 01:41
·
0 Likes
·
0 Votes
·
0 Comments
·
I will check with our developer regarding this.

By the way, glad to hear that your issue has been resolved now.

As a gentle reminder, kindly start a new thread if you have any other issue in the future so it will be easier for us to manage your inquiry. I will lock and mark this thread as resolved.
·
Tuesday, 07 February 2017 01:49
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post