Forums

Getting User ID to filter DB

har7801 17 May, 2018
Ive read dozens of forum articles on this but it seems they are all written for v3, v4 and v5. I want to get the logged in user ID to return data from a separate table that isn't the users database. I dont want to mess with the Joomla User DB, so have a separate sheet.

I have the form already and collects data, profile_ph, profile_address, profile_emconph, profile_emconnm, and the usual other fields auto populated, and the chronoform auto captures the user id that completes the form to the user_id field.

I want the member to be able to click on the web link that they used to fill in the form, but with their data so they can edit it if they need to and then resave it.

I just can't get the user_id filtering bit working in chronoform V6. Ive tried the CC code from other posts:

<?php
$user = JFactory::getUser();
$form->data['user_id'] = $user->id;
?>

with this in the RD:

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

and all iterations of it, but with a Model name keeps coming up as the error, or some other error.

Im even happy to build it into CCv6, and can call the data in that already, but only for the individual by putting a filter into the 'Where Condition' for the DB Read, something like:

Profile.user_id:546

Basically filtering per user, but need it to read from the logged in user automatically and adjust that condition.
Even tried Profile.user_id:$user, obviously wrong, but don't know any better.

Thanks in Advance.
har7801 18 May, 2018
Thanks a tonne.....again.

You would have though I would have tried that considering the questions I had alread asked re other issue, but didnt even occur to me.

Last one on this (I hope)

I can get the results to return now, can see that in the debugger, and can load them into a CCv6 table to view, but am trying to get them to reload into the CFv6 form fields.

I know its just a simple issue but can't see it.

In the name field for the text box I've tried, Profile.phnumber, Profile[phnumber], read_data4.phnumber, read_data4[phnumber] or just phnumber,

Just cant get the reload!!!!!!!

Profile being the Model, read_data4 being the Read DB function, phnumber being the DB field to read. I know the data is lading to the page, can see it in the debugger. Im missing something real simple I'm sure.
healyhatman 18 May, 2018
{var:read_dataaction.model.field}
har7801 18 May, 2018
Ok Im poasting this:

{var:read_data4.Profile.phnumber}

into the name filed of the text box, still nothing. Pic of debugger:

har7801 18 May, 2018
Have tried that too. Still nothing.
healyhatman 18 May, 2018
are you loading it before you display your form, in the same event? Otherwise how are you passing through value?
har7801 18 May, 2018
Yes , the read data is before the Display Section in the load area.
healyhatman 18 May, 2018
1 Likes
you have it set to return all records don't you? Set it to first matching or do var:read data.0.model.field. I'd go with option 1.
har7801 18 May, 2018
Yes set to All Matching. Ill try the other options to test.
har7801 18 May, 2018
Set to First Matching did it. FFS, such a simple miss.

Thsnks a Tonne again, they owe you a payrise.
healyhatman 18 May, 2018
They don't pay me I don't work for them I'm just another user.

I take donations though haha

Paypal.me/healyhatman
har7801 18 May, 2018
Last and absolutely the Last I hope.

Got it all working, reading, writing, get the data from all the tables, then, I get duplicate records each time I hit Save Button. No probs, dropped in a hidden field into the form, loaded the AID into it using {var:read_data4.Profile.aid} in the value, named it the same as the field 'aid' so it writes back to the table and uses the same entry, but I get a 'Duplicate Copy' error for the AID.

Again I know its going to be simple but I'm missing it.
healyhatman 18 May, 2018
Answer
1 Likes
You need to add the id to the update condition and make sure your save data action is set to "insert - updatr on duplicate"
har7801 18 May, 2018
Set the DB Read to 'Insert - duplicate key update' as suggested and BOOM, we are away.

Thanks. Now I can put this puppy to bed and call it done. Until the next project, sure that wont be long.
This topic is locked and no more replies can be posted.