Forums

Exporting flat array form data to CSV

JacquesR 21 Sep, 2016
I'm attempting to export form data (from a "flat" array) to a CSV, using the CSV Export v2 [GH] action.

I've followed the steps in the How can I link two DB Multi Record Loaders? article, and that was very helpful to show the data, but I get stuck in adding the extra step to export that form data.

I followed the advice in that article to convert the data array (adapting the example code provided), to a "flat" array, so the debug shows the form data as:


Array
(
    [option] => com_chronoforms
    [chronoform] => export-download-data
    [MyTest] => Array
        (
            [0] => Array
                (
                    [title] => Document A
                    [created_on] => 2016-09-19 12:29:28
                    [id] => 289
                    [name] => John Smith
                )

            [1] => Array
                (
                    [title] => Document B
                    [created_on] => 2016-09-19 09:20:17
                    [id] => 289
                    [name] => Bob Jones
                )

            [2] => Array
                (
                    [title] => Document C
                    [created_on] => 2016-09-19 09:18:05
                    [id] => 289
                    [name] => Jane Green
                )

        )

)


Using the example array above, what exactly would I enter in the Data Path field of the export action? I tried MyTest but nothing is exported. Am I missing a step, or am I not entering the Data Path correct?

Your guidance would be appreciated.

(I did have a look at all the forum posts I could find, that may relate to this, but could not find where I'm going wrong)
GreyHead 21 Sep, 2016
Hi JacquesR,

Using MyTest as the Data Path looks correct to me. Are you seeing any Debugger output from the CSV Export action? There should be a file link and size I think.

Bob
JacquesR 21 Sep, 2016
hi GreyHead

I see the following on the next page, after clicking submit:

Data Array: 
Array
(
    [option] => com_chronoforms
    [order] => email
    [direction] => desc
    [chronoform] => export-download-data
    [event] => submit
    [input_submit_1] => DOWNLOAD
    [790a20b9163d88aae3472d1729d806c8] => 1
)
Validation Errors: 
Array
(
    [CSV Export] => No records were found to export.
)


and Debug Data:

CSV Export
$download_export: 1
$download_nosave: 1
Download 'No Save' is set so no folder is created.
File name is: 
csv_export__201609211729.csv
GreyHead 22 Sep, 2016
Hi JacquesR,

There doesn't appear to be any data there to export?

I suggest that for debugging you set the export csv file to save to the server - the immediate download can stop you seeing the debugger output.

Bob
JacquesR 23 Sep, 2016
hi Bob

I tried your suggestion, but the result remains:
[CSV Export] => No records were found to export.

Are any of the fields in the export action required, apart from the Data Path?

Jacques
GreyHead 23 Sep, 2016
Hi Jacques,

I don't think so.

Bob
GreyHead 23 Sep, 2016
Hi Jacques,

The problem is that you are loading the data in the On Load event and trying to export it from the On Submit event - there is nothing to pass the data between the two so that there is no data to export. I've made a copy of your form and replicated the DB Reads in the On Submit event - the export there includes the data.

I'm not quite sure what you want to do here. You could add the data to the Joomla! Session - that way it would be available to the On Submit event; or you could just pass a list of record ids to the On Submit event and re-look-up the selected data there.

Bob
JacquesR 23 Sep, 2016
Thanks Bob,

Thank you for solving the puzzle. I see now where I'm going wrong.

The main purpose of the form is to export the combined data from the two tables. The Display part is less important.

I now have to figure out how to add a filter field. This was fairly easy when the CSV export action was using a table, but more tricky with form data.

Thanks for your help!
GreyHead 23 Sep, 2016
Hi Jacques,

What do you need to filter? You should be able to add that using the Conditions box in one of the DB Read actions.

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