Forums

Save field data to different database tables

Elisah 13 Feb, 2015
Hi! I work with a lot of forms within my website. To preserve a clear overview I would like to narrow down the number of forms (that serve the same purpose) as much as possible. So here's my question: I have 1 form and I would like to save the field data so several database tables (a table per client).

For instance: the form should start with a dropdown. Based on the selected value (which would be the client number), the rest of the form fields should be placed in the associated database table. So if I select option 1 in the dropdown, I want all the form data to be saved in table 1, if I select option 2 from the dropdown alle the data should be saved in table 2 etc. This way I hope I don't have to create one form per client.

Basicly, it would be perfect if the initial dropdown would show the client number as the title, and that the value would hold the database table to initiate of trigger some sort of action to save the data to this table.

Ik hope my question is clear and that this can be done. Thanks a lot!
Elisah 13 Feb, 2015
I have seen all of these post, but it doesn't help. It's to specific I think.
GreyHead 13 Feb, 2015
Hi Elisah,

I don't think that you can dynamically set the form name in ChronoForms DB Save action. But you can if you hand-code the DB Save in a Custom Code action.

If you add a Debugger to the current form you can see the MySQL query that ChronoForms creates and use that as a starting point.

Bob
PS Why do you need to use a different table for each client - it would be simpler to add a client column to a single table?
Elisah 13 Feb, 2015
Hi Bob,

my goal is kind of difficult to explain (and maybe i'm making it way to hard), but i'm working towards a customer portal. The objective is to create a (massive) table per client which holds all the information of services they use. Clients should be able to edit their own information trough forms (via chronoconnection). Each form edits part of the massive tabel. And I also don't want clients to view another clients information of course. Is this even possible? Do I need to work with a model id, because I don't nog how to do that.

Here's the debugger info. I changed some of the values to cover some information.

----------------------------------------

Array
(
    [1] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `jos_TABLENAME` (`field1`, `field2`, `field3`, `field4`, `field5`, `field6`, `field7`, `field8`, `field9`, `user_id`, `created`) values (`value1`, `value2`, `value3`, `value4`, `value5`, `value6`, `value7`, `value8`, `value9`, '344', '2015-02-13 15:34:46');
                        )

                )

        )

    [2] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:website@domain.nl
                    [2] => Subject:E-mailalert
                    [3] => From name:xxx
                    [4] => From email:info@domain.nl
                    [5] => CC:
                    [6] => BCC:email:info@domain.nl
                    [7] => Reply name:xxx
                    [8] => Reply email:email:info@domain.nl
                    [9] => Attachments:
                    [10] => Body:
....bodytext...
                )

        )

)
Max_admin 13 Feb, 2015
Hi Elisah,

You mean each user has its own data table ? or its only 1 table where all data is stored ?

If its the 2nd option then this should be easy and has been discussed here many times already!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 15 Feb, 2015
Hi Elisah,

it is possible to do this with one table for all clients (very simple) or with separate tables for each client (quite difficult).

At the current stage of development I would work with one table. Once you start getting problems with the size of the tables (they can be very big) then you will have enough experience to split them up.

You'll need to add a 'client_id' column to the table - probably linked to a User ID or a User Group and check for this when the table is loaded so that you only get records for that particular client.

Bob
Elisah 16 Feb, 2015
Hi Bob,

I'm gonna try this. If I encounter any issues I'll be back ;-)

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