Retrieving ID after saving data to use in another form

cmwincom 24 Apr, 2024

I have a form where I collect basic team information. When the form is submitted the data is saved to a teams table and gets a tmID (autoincrememnt), which is the primary key of that table. Then the user is redirected to a second form to add team members, for that team, to the team_members table. I need to get the tmID value that was created when the team information was saved so that it can be added to the team member data when the member is saved. What is the best way to achieve this?

Max_admin 24 Apr, 2024

disable the redirect and enable the form debug, the debug will show you the id returned from the "insert" under the "Vars" section under the "save_data" action part 

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
cmwincom 25 Apr, 2024

I've done that. For the last test entry I get: 

[tmid] => 14

How do I get that value into my second form to add team members? Do I need to set it as a variable and if so, how? Then how do I reference it or call it in the second form?

Max_admin 25 Apr, 2024
Answer

You better append it to the redirect url and get it in the 2nd form as a data variable, so in your redirect parameters you can use:

tmid={var:save_action_name.id}

and in your 2nd form:

{data:tmid}
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
cmwincom 27 Apr, 2024
1 Likes

Thank you. Got it working just the way I want it to.

You need to login to be able to post a reply.