Buy Now
Sign in

Getting User ID to filter DB

har7801 , May 17 at 12:58
Answered
H
har7801
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.
H
healyhatman
{user:id}
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
H
har7801
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.
H
healyhatman
{var:read_dataaction.model.field}
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
H
har7801
Ok Im poasting this:
{var:read_data4.Profile.phnumber}
into the name filed of the text box, still nothing. Pic of debugger:
Capture.JPG
Attachments
Capture.JPG
Capture.JPG
(75.27 KiB)
112 Downloads/Views
H
healyhatman
Put it in the VALUE buddy
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
H
har7801
Have tried that too. Still nothing.
H
healyhatman
are you loading it before you display your form, in the same event? Otherwise how are you passing through value?
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
H
har7801
Yes , the read data is before the Display Section in the load area.
H
healyhatman
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.
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
H
har7801
Yes set to All Matching. Ill try the other options to test.
H
har7801
Set to First Matching did it. FFS, such a simple miss.
Thsnks a Tonne again, they owe you a payrise.
H
healyhatman
They don't pay me I don't work for them I'm just another user.
I take donations though haha
Paypal.me/healyhatman
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
H
har7801
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.
H
healyhatman
You need to add the id to the update condition and make sure your save data action is set to "insert - updatr on duplicate"
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
H
har7801
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.