Forums

Two Database save Action

Dhananjay 08 Aug, 2013
Hi all

I am using 2 database save actions on submit event, saving data to 2 different DB table respectively.
Both are working very fine – both increments a single row on form submission
The first DB save action is used to save unique payment order details–each time the form is submitted.

I want to use 2nd DB save action for data base record loader –That means it must update the form record and not create a new row of table record on the form submission.so that the form is pre loaded with last updated data when the next time user visit the page

My problem is – I want one table to be incremented on each form submission and other table to be updated on same form submission
If I use cf_id in hidden form field it will just update both the tables

Hope the problem is clear
Is there any solution to above problem

http://www.astrodarshan.com/index.php/online-payment
username - demo7
password - demo7

Thanks
djay
GreyHead 08 Aug, 2013
Hi Dhananjay,

You can use a Custom Code action between the two DB Save actions to unset the cf_id value
<?php
unset($form->data['cf_id']);
?>


Bob
Dhananjay 10 Aug, 2013
Thanks Bob
For your reply and answer.

It worked very nicely for me.

For Knowledge of other forum members i am posting here my requirement and its solution

I have the chronoform which collects the user debit/credit card details (except card no.) to be passed to payment gateway. I am using GH unique id for generating unique order id.
http://www.astrodarshan.com/index.php/online-payment

Every new order is saved with its unique order id into the DB table. Now I can’t use that data into DB record loader coz single user may have more than one orders and the oldest record gets loaded.

So I have used two DB save action with 2 separate tables one for saving orders and others for re-loading the latest billing record when user visit the page next time to place new order.

The problem was that when I used cf_id as the hidden field it updates both the tables.
So as hinted by Bob I have used 1 DB save action above and other DB save action below the custom field having following PHP custom code--
<?php
unset($form->data['cf_id']);
?>
the table which is required to be updated -- its DB save action is placed above the custom code

Thanks
Djay
sahanashah84 13 Aug, 2013
Hi,

I am very new to Chronoforms myself and struggling a lot with DB Save to Multiple Tables from Multiple Forms. I have divided the Registration process into 2 different forms. I want to save the data of each on different DB tables. My issue is how to achieve: Form 1 Stores the Data on the Table1 which creates the PK for that Accounts "AccountID", Next Form2 Saves Data to Table2 and in this table there is FK which references the PK of Table1 "AccountID" so that I can Join the 2 tables and the data from one Account are reltaed though stored in different tables. Any ides?
GreyHead 13 Aug, 2013
Hi sahanashah84,

Please see this FAQ for the code to get the primary key value from the first save. You will then need to use a Custom Code action to change the name of this entry in the $form->data array to match the key column in the second table.
<?php
$form->data['key_for_table_2'] = $form->data['chronoform_data']['cf_id'];
?>




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