• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Creating a new row in another table with form php and mysql query

m6xmed5

Member
I'm trying to auto create a new entry in another table after a new data submission has been added and pre-fill some data into the second table. I'm aware we can get the next pk for the table the form relates to before saving the form by
PHP:
$rowid = JArrayHelper::getValue($formModel->formData, 'rowid', '');

Is there a similar way to do it for the other table but in the same form so that I can run a query to add a row to the other table with some data from this form?

Marc
 
Have you tried the upsert form plugin?

That allows two ways of inserting/updating another table after saving your main table, either with an FK on the main table pointing to the PK of the other table, or using an FK on the other table pointing to the PK of "this" table (rowid). The plugin then handles updating the FK element.

It's not a "core" plugin, so you'll need to either discover it in J!'s extension manager (if you've ever done a github update) or install it from the downloads area on this site.

-- hugh
 
Thanks hugh, I've had a play around with the upsert plugin but no joy. I need to use the id from the form the plugin is running on as the fk. Just messing around with some php to try and return that in the value field. I can't take it from the database as it hasn't been created until save is clicked.

PHP:
$rowid = JArrayHelper::getValue($formModel->formData, 'rowid', '');
$formModel->getListModel()->loadResult($rowid);

Doesn't work, I havn't done much php so I'm not sure how far off I am with this, can you give any pointers?
 
The upsert plugin definitely works.

Here's a screencast of it working in PK mode, where the FK is stored on the main table - so I have a join element on the main table pointing to the row in the related table I want to update. But it works just as well the other way round, in FK mode, where the FK is stored on the other table,, pointing to "this" row in the main table.

https://www.screencast.com/t/Bn1BaBBPzh

It's just a case of figuring out how to set it up.

Ignore the debugger that pops up in the video, I have some breakpoints set in the form code working on a different issue. The main takeaway there is the 'multi_dd' field in fab_main_test gets updated after submitting the Upsert form, using the values taken from the Upsert form, as seen in the Navicat view of the raw table data.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top