Forums

Recover info from logged in user

allemontanari 17 Mar, 2016
Answer
Hi,
I need to recover from a DB more information from users using DB Read:

In the OnLoad Event
I've created a Custom Code (that give me the id of online user)
<?php
$user = \JFactory::getUser();
$form->data['online_id'] = $user->id;
?>


and the DBRead configured as below
Table name: y90ms_users
Multi read:Yes
Enable Model ID:Yes
Model ID: *empty*
Fields: id, username, email
Conditions:<?php return array('id' => data['online_email']; ?>

When I test the form I receive the Array below:
Array
(
    [option] => com_chronoforms5
    [chronoform] => TEST_ReadDB
    [online_user] => test_user@gmail.com
    [Data] => Array
        (
            [0] => Array
                (
                    [id] => 12
                    [username] => test_user
                    [email] => test_user@gmail.com
                )
        )

)


and this one the Debug Info
Array
(
    [24] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data`.`id` AS `Data.id`, `Data`.`username` AS `Data.username`, `Data`.`email` AS `Data.email` FROM `xbduhikb_Jumpers` AS `Data` WHERE `Data`.`email` = 'test_user@gmail.com'
                        )

                )

        )

)


Seems that DB Read found my online user email on DB.

Now, if I want write some fields(id, username, email) of user in a text Box, witch sintax I need to use?
I've tried [email] or {email} or [data.email]....but doesn't work.

Thanks
GreyHead 17 Mar, 2016
Hi allemontanari,

If you only want to get the current users data please turn off the Model ID and the Multi settings, then {username} should show you the username in a Display Message element.

Bob
This topic is locked and no more replies can be posted.