05
Days
23
Hours
59
Minutes
59
Seconds
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: how to retrieve login user (ID, name,..) in the f

how to retrieve login user (ID, name,..) in the f 1 week 2 days ago #44150

  • fchan
  • fchan's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 17
Dear Sir,

as subject, I need to create a "course-registration-form"

1. need to retrieve a logged in student data in the form fields (user_id, username, name_hk, name_en, mobile, email) Once a student logged in success, he can visit the form and all above fields will be auto shown in those fields )

2. I need a checkbox list in which its id and value are retrieved from my datab table #__aot_course which allow student to have multiple select in checkbox list . thus the check box list should be created by sql statement likes ( Select id, name_en From #__aot_course where state = 1 ) are there any similar tutorial I can refer with ?

Thanks for your kind attention

Fion
The administrator has disabled public write access.

how to retrieve login user (ID, name,..) in the f 1 week 1 day ago #44152

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 271
  • Thank you received: 70
Yes, start here https://docs.joomla.org/Selecting_data_using_JDatabase

To get for example the user id
// Joomla 5+ way to get logged-in user
$user = \Joomla\CMS\Factory::getApplication()->getIdentity();
 
// Check if a user is logged in
if (!$user->id) {
    return; // no user logged in
}
 
// Store user ID
$userId = $user->id;

Now the $userId contains the users id which can be used to get further data like this
// Get database object
$db = \Joomla\CMS\Factory::getDbo();
 
// Build query
$query = $db->getQuery(true)
    ->select('*') // select all fields, or specify: member_number, phone, address
    ->from($db->quoteName('#__members'))
    ->where($db->quoteName('user_id') . ' = ' . (int) $userId);
 
$db->setQuery($query);
 
// Load result as an object
$memberData = $db->loadObject();

All this happens in the php pre processing script so once you have the data and assigned it to your form fields then it's prefilled for your user. You assign values like this
$val['expires']   = $row['renewal_date'];
If you can keep your head when all about you are losing theirs, you obviously don't understand the situation!
Last Edit: 1 week 1 day ago by iceferret. Reason: added info
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!