Populate form field with logged user data

Retinal 06 Mar, 2016
Hi!
I know that this subject has been treated several times (I read many topics) but I can not find a solution.
I would like to extract the data of the logged user, but my data are in another table (not #_users) so I tried to configure the DB Read module.

In Custom Code I set:
<?php
$user = JFactory::getUser();
$id = $user->id;
?>


In DB Read I set:

Table name: ysy6w_jsn_users
Multi read: yes
Enable Model ID: no
Fields: id, firstname, lastname
Conditions:

<?php
return array('firstname' => $form->data['firstname']);
?>


In Designer Section I put a Text Box
Field Name: firstname
Field ID: firstname


obviously missing something...


how can I populate my text box form with "firstname" recovering it in my table filtering it by logged user ID?

Many thanks!
Max_admin 07 Mar, 2016
Please disable "Multi read".

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 07 Mar, 2016
Hi Retinal,

The #__users table doesn't have first_name or last_name columns, just name.

And you don't need the database query - all of the information in #__users is available in the $user object that you already have to get the id.

Bob
Retinal 07 Mar, 2016
Hi GreyHead,
thanks for your reply.
I know that #_users table has no lastname and firstname columns but I use EasyProfile component for my users so I need to get user Id to use it (like a Join) to extract some value from #_jsn_users (that is the EasyProfile table).

So I would like to get user ID with Custom Code:
$user = JFactory::getUser();
$id = $user->id;

and in DB Read function I set the EasyProfile table #_jsn_users and I would use the logged user id as a key to extract user data and fill my text box.

Can you help me?

Many thanks!
GreyHead 07 Mar, 2016
Hi Retinal,

What is the name of the User ID column in the Easy Profile table?

Bob
Retinal 07 Mar, 2016
Hi!
The User id column is "id"
Thanks
GreyHead 07 Mar, 2016
Answer
Hi Retinal,

Then in the Custom Code action add:
<?php
$user = JFactory::getUser();
$form->data['user_id'] = $user->id;
?>

In DB Read set:
Table name: ysy6w_jsn_users
Multi read: No
Enable Model ID: No
Fields: id,firstname,lastname // note - no spaces here
Conditions:
<?php
return array('id' => $form->data['user_id']);
?>

Add a Debugger action after the DB Read to check that you are getting the data you need.
Bob
Retinal 07 Mar, 2016
GreyHead you are great!
Seems it work perfectly.

Many thanks!
This topic is locked and no more replies can be posted.