ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Save user:id immediately after creating one

omidhz 02 Jul, 2017
I have a customized user registration form that it supposed to work like this (and in this order):
1- Register new user in default joomla user table
2- Send email to user
3- Automatically log in the user
4- Get the logged in user ID and save it to "relationship" table
5- Redirect user to welcome page.

My problem is that step 4 is saving user ID as 0 to the second table when it is run for the first time. I know the codes in my save data is correct because if I repeat the above steps without logging the user out, it then saves the user ID correctly.

I believe what is happening here is that Step 4 is happening so quick that it is not getting the user ID returned from the database.

How should I fix this problem? Do I need to a pause in the process? How?
I attached a screenshot of the process section and also the save data action for saving the user ID to second table.
Thank you in advance.
Max_admin 26 Aug, 2017
Hi omidhz,

You can save the id returned from the "save user" result in #1, you can find the data path when you run a debugger after that action.

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
omidhz 14 Oct, 2018
I was able to figure this out and it was working for a while, now it has stopped working. I'm not sure if one of the recent updates broke this function or if I'm doing something different. Here is what I have
I use a custom registration form. After user's data is saved to the Joomla user table using the save user module with the name: joomla_user4, I'm using the following custom php code to get the recently created user ID:
$this->data['user_ID'] = $this->vars['joomla_user4']['id'];
Unfortunately, this is not returning anything:


I'm then using the save data to save the user ID to a different table using the following code in the data override on insert:
user_ID:{data:user_ID}

Here is the debugger:
Array
(
    [option] => com_chronoforms6
    [chronoform] => registration
    [event] => submit
    [name] => John Smith
    [email] => jonny@test.com
    [password] => 123456789
    [g-recaptcha-response] => 03AMGVjXilE_PBPXHn5AH2J3N1trTf7XdG-x68WQwV6J4j2A4JaMj4SQXwmHLkEjMNBhbJZDHPPVNgGor420NHxOwROhHknTNWo-PZW3ebBukdvQ9QfnyvyEJV8FRU4hR2FvwannLKs_m5Ig2--6PJYptHk8JM1LDzMiLGppHYe81XdSQvGOlqaP3vIC0W5uT_HESdn6uCXAea4bMf1SRyrIIlyiVUyoaPkJ1BUONnD9_dF1NsGGtGorLt6Z0HodMeOPmhboTMw5-PIq7OTz8a_XuKGBZWmOyvzg
    [button] => 
    [9d4bb4a09f511681369671a08beff228] => 76e101aec449337e7686cb3312a1fe71
    [cadc1bee9ebcbe83759a5448896141ea] => 55759d16ef58d50fc48fc0b8c1cfafed
    [joomla_user_state] => logged_in
    [b55ccf54e939410eb7e9815e153c81c9] => 5a65d4fff3f6ce08101b73f44bceeaf7
    [Itemid] => 
    [user_ID] => 
)

Array ( [validate_fields2] => Array ( [log] => Automatic validation enabled. [var] => 1 ) [google_nocaptcha3] => Array ( [response] => Array ( [success] => 1 [challenge_ts] => 2018-10-14T18:26:22Z [hostname] => mybiophysical.com ) [_success] => The NoCaptcha verification was successfull. [var] => 1 ) [joomla_user4] => Array ( [_success] => User saved successfully under id 807 [var] => Array ( [name] => John Smith [username] => jonny@test.com [email] => jonny@test.com [password] => 123456789 [block] => 0 [activation] => [registerDate] => 2018-10-14 18:27:10 [id] => 807 ) ) [get_logged_user_id] => Array ( [returned] => [var] => ) [save_data20] => Array ( [data] => Array ( [option] => com_chronoforms6 [chronoform] => registration [event] => submit [name] => John Smith [email] => jonny@test.com [password] => 123456789 [g-recaptcha-response] => 03AMGVjXilE_PBPXHn5AH2J3N1trTf7XdG-x68WQwV6J4j2A4JaMj4SQXwmHLkEjMNBhbJZDHPPVNgGor420NHxOwROhHknTNWo-PZW3ebBukdvQ9QfnyvyEJV8FRU4hR2FvwannLKs_m5Ig2--6PJYptHk8JM1LDzMiLGppHYe81XdSQvGOlqaP3vIC0W5uT_HESdn6uCXAea4bMf1SRyrIIlyiVUyoaPkJ1BUONnD9_dF1NsGGtGorLt6Z0HodMeOPmhboTMw5-PIq7OTz8a_XuKGBZWmOyvzg [button] => [9d4bb4a09f511681369671a08beff228] => 76e101aec449337e7686cb3312a1fe71 [cadc1bee9ebcbe83759a5448896141ea] => 55759d16ef58d50fc48fc0b8c1cfafed [joomla_user_state] => logged_in [b55ccf54e939410eb7e9815e153c81c9] => 5a65d4fff3f6ce08101b73f44bceeaf7 [Itemid] => [user_ID] => [created] => 2018-10-14 18:27:10 ) [_success] => Data saved successfully [log] => Array ( [0] => INSERT INTO `hs_response` (`name`, `user_ID`, `created`) values ('John Smith', '', '2018-10-14 18:27:10'); ) [var] => Array ( [name] => John Smith [user_ID] => [created] => 2018-10-14 18:27:10 [id] => 121 ) )
I really appreciate any help here.
Thanks in advance
healyhatman 15 Oct, 2018
Get the user id with {user:id}
Get the id of a record saved by a save data action with {var:save_data#.id} after replacing # with the corresponding number of your action.
omidhz 15 Oct, 2018
Thank you
healyhatman 15 Oct, 2018
Get the id of the user you created with {var:joomla_user#.id}
omidhz 19 Oct, 2018
I'm still struggling to make this thing work and I'm lost on how to fix this.
Here is the scenario again,
What I need to happen:
- Custom user registration form, registers the user in joomla_users table, then logs in the user immediately, then it gets the logged in user ID and saves it in mb_profile table.
- mb_profile table has a column named user_ID which is a foreign key to the parent table joomla_users linked by the id in that table. The purpose of this is that if I delete a user from joomla, it's data gets deleted in the mb_profile table as well.

Here is my problem.
When I test the custom registration form without adding the save data function to save ID to mb_profile table, everything works as expected and user gets registered and then logged in.
When I add the save user id function to my form AFTER user is logged in, I get the error message:
1452 Cannot add or update a child row: a foreign key constraint fails (`my_joomla_db`.`mb_profile`, CONSTRAINT `user_ID Relation` FOREIGN KEY (`user_ID`) REFERENCES `#__users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)


When I delete the foreign key relation in my database just to test the save function, the returned user ID is 0 and it doesn't save it in my mb_profile table.

I thought maybe this is due to fact that all functions are happening simultaneously and too close to each other. So I added a php command to sleep(5); after Joomla log in then to save the user ID to the second table, but still the same issue.

To see if my save function is working correctly, I created a test form, with only that save user ID function and when I test that separately, it saves the user ID to the mb_profile table without any errors. So I know that my save function is coded correctly.


I will definitely donate to the person who provides me with the solution to this issue. I can also share my form file with you if you like.
Thank you in advance.
healyhatman 19 Oct, 2018
Answer
doesnt matter that they're close together. And you can get the id of the just-created user with {var:joomla_user#.id} where joomla_user# is the name your your save user action.
omidhz 19 Oct, 2018
That did the trick. THANK YOU. I was using {user:id} expecting it to work properly and it was returning 0.
Thanks again.
healyhatman 19 Oct, 2018
No problem, I did initially mistakenly tell you to use {user:id}, but then I corrected myself in the post after that with {var:joomla_user#.id}
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com