I need to add the usergroup of the user that is logged in the confirmation email, like " You are logged in as xxx user"
Any advise how to do that?
you will need a Read Data action to get you the group name from the groups table based on the user's usergroup, you can get the user's groups with {user:groups}, but this will return an array
thanks for your answer, but as far as I see, ther is no data read action in CF5.
I tried the following Custom Code in the setup section:
<?php
$user = JFactory::getUser();
if ($user->id) {
$mainGroupId = $user->get('gid');
$mainGroup = $user->get('groups');
$Usergr = $mainGroup[$mainGroupId];}
?>
and added the following line in the Email action, email template:
....
<tr><td>Usergroup: {Usergr}</td></tr>
....
What did I wrong?
Regards
kraadde
now I have found the solution:
correct code to retrieve the usergroup:
<?php
// Load the Joomla user object
$user = JFactory::getUser();
// Check if the user is logged in
if (!$user->guest) {
// Get the user group IDs
$userGroups = $user->groups;
// Load the Joomla database
$db = JFactory::getDbo();
// Query to get the group names
$query = $db->getQuery(true)
->select('title')
->from('#__usergroups')
->where('id IN (' . implode(',', array_map('intval', $userGroups)) . ')');
$db->setQuery($query);
$groupNames = $db->loadColumn();
// Join group names into a string
$groupNamesString = implode(', ', $groupNames);
// Save the group names into a form variable
$form->data['user_groups'] = $groupNamesString;
} else {
$form->data['user_groups'] = 'Guest';
}
?>
you are using v5 ? I thought you are using v8
Thank you for posting the solution