Forums

Howto save one field in two tables

pieter 22 Mar, 2012
I am learning ChronoForms V4 and I do have a lot of fun with it and really love it.... but..

I managed to have one form save into two tables, but that is when one field is going into one table.
I cannot find a way to save one field into two different tables...
Is there a way of doing this?

Thanks,
GreyHead 22 Mar, 2012
Hi pieter,

What is saved depends on the input and column names; if they match then the data is saved. If both columns have the same name this should work, if the secodn column has a different name then you need to use a Custom Code snippet to copy the value into a new entry in the $form->data array to match the second column name.

Bob
pieter 22 Mar, 2012
Thanks for your early reply. This makes things clear.

So if I have two different column names I can create a custom code like

<?php $form->data['user_user'] = $form->data['assign_user'] ; ?>


Do I put this in the events before the DB Save actions?

Thanks!
GreyHead 22 Mar, 2012
Hi pieter ,

Yes, exactly like that. Drag a Custom Code action into the event and move it up before the DB Save actions.

Bob
pieter 22 Mar, 2012
Thanks,

I only don't get it to work... is my syntax ok?
Is $form->data['bladibla'] working in this way or can it onlt work when there already is something in the table?

Or is my better option to rename the column?
GreyHead 23 Mar, 2012
Hi pieter,

It will work provided that there is data in the $form->data array, adding a Debugger action temporarily will tell you what is there.

If it's simple to do and doesn't affect other places the table is used then renaming the column is fine.

Bob
pieter 23 Mar, 2012
Thanks,

there is no data as it has to be submitted first.. (I think) ... renaming the column did the trick for me...

Thank you for your help on this.
This topic is locked and no more replies can be posted.