Forums

DB Store doesn't work on table created with "Create table"

jcalvert 23 Jun, 2014
I found out the hard way that "DB Store" won't work with a table created with "Create table".

This post finally gave me the clues I needed to solve this: http://www.chronoengine.com/forums/posts/f26/t90090.html

The reason DB Store is not working relates to the fact that the "id" field of $form->data contains the Joomla article id. This then apparently erroneously gets used in the DB Store function to look up the database record in the table with the corresponding id, resulting in MySQL UPDATE getting used (and failing) instead of INSERT INTO. Note that the first field of the table created by "Create table" is "id", which apparently is the cause of the problem – it's the same label as "id" in $form->data.

In order to patch this problem, I made the following change to ./administrator/components/com_chronoforms5/chronoforms/actions/db_save/db_save.php :

After line 48:
$data['user_id'] = $user['id']

Add:
$data['id'] = '';

JC
GreyHead 23 Jun, 2014
Hi jcalvert,

It used to be cf_id in CFv4 - I'm not sure why Max changed that.

You have a couple of choices without hacking the core code:

a) in the Create Table page change the Field Title from id to say cf_id - that will avoid the potential clash with article ids.

b) If its too late to do that add a Custom Code action before the DB Store action and add code like this:
<?php
unset($form->data['id']);
?>

Note: you only need to do this if there is a problem because of the article id being picked up from the page URL.

Bob
jcalvert 23 Jun, 2014
Thanks. Is there a way to delete the "Connected table" through CF admin?
jcalvert 23 Jun, 2014
I was able to delete the connected table by deselecting it in Setup, DB Save. Then using Create table again, giving it a new name. I also deleted the table using phpMyAdmin. A note to anyone reading this... remember to select the new table you just created using Setup, DB Save.

I was not, however, able to get either of your suggestions to work. I have kept my core hack and it is working.

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