How do I refer the auto-increment ID to another field when adding a new record?

AlainR

Member
I would like to create a record with a Fabrik form and I need to save the automatic ID also in another field.
In fact, the Fabrik form will take action on 2 linked tables (not created by Fabrik) and, if added, I need to be able to create and link the records of the 2 tables by saving the ID of form 1 in the parent_id field of form 2.

What is the best way to do this, please?
 
Not sure about your full setup, but if the other tables are joined to your main table like on maintable.id = secondtable.parent_id, fabrik fills the parent_id field automatically on form save.

Otherwise you can use form php-plugin (onAfterProcess), get the newly added rowid and update it to related rows with sql update query. See:
 
You're right ! I test it this morning and I see that fabrik fills the parent_id field automatically on form save.

I saw the page you mention and I find something odd : is there en error in the first example ?
")" is missing. And when I test, I had to write JFactory and not only Factory (J! 4.4.2). Do you confirm ?
 
Yes, there was a missing ")", fixed now.

$mydb = Factory::getContainer()->get('DatabaseDriver');
should be the correct syntax with J4/F4. That is weird you needed JFactory...
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top