Forums

can't post to multiple tables

marklandry 19 Sep, 2011
Hi
I'm using CF V 4 and Joomla 1.5.23.

I'm trying to connect and post to 2 tables and can only seem to post my info to one table at a time.

I have two DB SAVE elements in the events panel, and both work independently (ie if I only have one in the events area it does fine.) When I add the second, only one table gets it's info, the one listed first in the events pane.

Thanx for your help

Mark
GreyHead 19 Sep, 2011
Hi Mark,

It took some digging but I found the bug.

Please edit administrator/components/com_chronoforms/form_actions/db_save/db_save.php and look for this line around line 94:
$form->data[$model_id][$primary] = $form->data[strtolower($model_id.'_'.$primary)] = $row->$primary;
and replace it with this line (just deletes the first part)
$form->data[strtolower($model_id.'_'.$primary)] = $row->$primary;


What is happening is that the first DB Save code adds the new record id into the saved data; the second DB Save then sees the primary key and tries to update an existing record instead of writing a new one. Except that there is no existing record to update as the table is different.

NOTE: this fix may have side effects on other actions if they use the saved data - I don't think there are any but I'm not certain.

Bob
marklandry 19 Sep, 2011
I actually had Model ID in both elements set to the same thing "chronoform_data"
I changed one to chronoform_data2 and it works...

I would have caught that if I had read the tips a bit more closely.

Thanx again for the help.

Mark
GreyHead 19 Sep, 2011
Hi Mark,

Yes changing a Model ID will work perfectly too (though I still think it should work without having to do that).

Bob
raihan 15 Feb, 2013
Hi, I wish to post different fields to different table, but data to be entered in one form. How it can be done, pls?

In other way, when I drag any elements, say 'text box' - how I can assign that to any specific fields in any specific table?

Thnx in adv. Raihan
GreyHead 15 Feb, 2013
Hi Raihan,

You can use as many DB Save actions as you like, just make sure that the input names* match the column names in the table that you want to save the data into.

Bob

* Actually the names in the $form->data array that ChronoForms uses, so you can use PHP in Custom Code actions to change this if you need to.
raihan 17 Feb, 2013
Hi bob,

Thank you for your reply.

As u suggest me, it's working. I enabled or disabled some of the columns from alternate tables.

But, now I have add 'Add more' buttons in my form, which eventually take 5 records. But its not posting to Database. My tables having only the first record. And in the 'Create Table' showing error in field names like: 'Field name "addone_{$j}" is invalid'. I have used the example from the FAQ, to create the 'Add More' button.

What I may can do please? Thank you.

Raihan
GreyHead 17 Feb, 2013
Hi raihan,

That depends on how you plan to store the repeated data. There is another thread here with a discussion about this.

Bob
This topic is locked and no more replies can be posted.