hi,
would know anybody tell me if it is possible to submit a form (chronoform), save some data in a table, retrieve the id and save the rest of the data in another table associating the id retrieved?
Thank you very much
Hi danilodf,
Yes, that's not difficult, after the first DB Save ChronoForms adds the data saved, including the id to the $form->data array so you can use a Custom Code action to copy the id to a entry in the $form->data array with a name matching the column in the second table and do another DB Save.
Use Debugger actions temporarily to show you what data you have and where it is currently available.
Bob
Ok, I tried it and it works to some extent.
before:
The form data were stored in a single table (Table1).
after:
I created another table (Table2, for the time being with the same fields of Table1).
I entered a field in Table1 more in what I have called IdTable2.
The first DBSave, save a part of the form data in Table2.
With a Custom object id pull out the last of Table2
The second DBSave saves the rest of the data in Table1 including idTable2.
The only problem is that in Table2, with the 1st DBSave is created only a new record but without data from the form.
Instead, in Table1, with the 2nd DBSave, saves everything.
Since the tables are identical, I expected would save all the data in both cases ...?!?!?!
It seems as if the fields are coupled to Table1 as originally !!!
Thank you
Hi danilodf,
I would expect that the data would save in both tables. If you add Debugger actions you should be able to work out what is happening.
BUT why would you want to save the same data to two tables?
Bob
Hi Bob,
no, I do not have to save the data in two tables is only a test to see if I understood what I had suggested🙂
The data that was saving first in a table, now except in two separate tables but linked with an appropriate id.
Instead of separate things to try, I added a custom DBSave and the object.
I was expecting two saves equal, however in debugging the first insert presents only the user and the date, while the second insert has all the form fields.
what is wrong?😟
:?
Hi danilodf,
Please drag a Debugger action into the On Submit event, then submit the form and post the debug results here.
Bob
The first DBSave has "Data2" as Model_ID and the option "Save under Model id" to yes.
The Second DBSave has "Date" as Model_ID.
With the subject "Custom" extract the Id of Table2 in the following way:
<? php
$ db = & JFactory :: getDBO ();
$ form-> data ['idTable1'] = gcore\Models\Data2 :: getInstance () -> id;
$ query = "SELECT id FROM zul4a_chronoengine_chronoforms_datatable_Table1 WHERE id = '". $ form-> data ['id']. "'ORDER BY id DESC LIMIT 1";
$ db-> setQuery ($ query);
?>
After submit, before and debugging, also I see this error:
Notice: Undefined index: in Data2 C:\xampp\htdocs\Site\administrator\components\com_chronoforms5\chronoforms\actions\db_save\db_save.php on line 45
Notice: Undefined index: id in C:\xampp\htdocs\Site\administrator\components\com_chronoforms5\chronoforms\actions\custom_code\custom_code.php(20) : Eval () 'd code on line 4
Attached are debugging.
thank you
Hi Bob,
you've got to check out what I've posted?
I have done other tests but without positive results. 😟
Do you have any suggestions?
Thank you very much
Danilo
Hi,
I have some news.
In the first DBSave I set the "Save under model id" to NO.
Now, the first insert is done properly but the second DBSave performs an update because it considers "id" the IdEtichetta the first table!?!?!?
Maybe, it is wrong the custom control?
Danilo
Hi,
the issue described, it may be caused by a bug?
Thank
Danilodf
The value of the inserted record primary key will be added to the data array after the db save, which in your case I believe is 1, then you can use a new db save, but you should copy the value to a new field matching the foreign key's name in the 2nd table, and if the 2nd table's pkey is also "id" then you must unset the id value in the data array:
<?php
$form->data["2nd_table_fkey"] = $form->data["id"]; //assuming pkey in 1st table is "id"
unset($form->data["id"]); //assuming pkey in 2nd table is also "id", and so we need to remove this value to avoid an update
The code above should be inside a "custom code" action before the 2nd db save.
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?