Forums

Creating a CSV Download

U Can Drive 19 Jan, 2019
I have created a form that displays a list of multiple field entries from a database read.
Basically using the {var:area_repeater7.row.Report.Name} value.

I'm using a single read data action to do this (below)

How do I move this data into the CSV action?
Are there steps that should be between the "Read Data" and "CSV" actions?
What goes in the "Data Provider" and "Titles" boxes in the "CSV" action?

All I'm getting is a spreadsheet in Excel with the cell A1 displaying "" and the webpage freezes.

Thank you in anticipation of a response🙂

healyhatman 19 Jan, 2019
1 Likes
{var:read_data#.[n]} for the data source, replace "read_data#" with the correct name of your read data action or var array

model.field:Name for the Titles
U Can Drive 20 Jan, 2019
Thank you for your quick response...

The result I'm getting is the correct headers across the top, but the first column states "Array" in each cell, the correct number of times🙂 but nothing in the rest of the sheet.

Is there supposed to be something specific in the place of the [n] ???
Or something specific to deal with it being an Array ?


healyhatman 20 Jan, 2019
Is Report the right name of your model? Including the correct capitalisation? Same with the names of the fields?

And can you post a debug?
U Can Drive 20 Jan, 2019
The "Read Data" entries are in the first post, in that one the Model name is "Report" with a capital R.
I can't do a debug while the csv action is there as the page freezes with the download circle continually going round, but if I remove the csv download I get this:
Array
(
    [option] => com_chronoforms6
    [chronoform] => Report
    [event] => ReadReport
    [StartDate] => 14/01/2019
    [EndDate] => 14/01/2019
    [Instructor] => 071266767
    [Request] => 
    [_ga] => GA1.3.1615824038.1546349699
    [fbm_1635736963332990] => base_domain=.ucandrive.com.au
    [_gid] => GA1.3.1428903841.1547987188
    [_fbp] => fb.2.1547987188418.1676878659
    [df095ea18f45903807902fe9758177c0] => 1br1428ldc4sgs0apt757qai13
    [ac2664da8cb0e5732104ddf8c4826d71] => 2cm90f7gujrnm3dmmmm0lcbg34
    [joomla_user_state] => logged_in
    [joomla_remember_me_a1357ebe2d0a9c74257f0eff8c469fcb] => 2xZQbP7fnCB1lKJ7.ZTFv4Drrr4c6pz3sMcwU
    [_gat] => 1
    [Itemid] => 
)
Array
(
    [validate_fields2] => Array
        (
            [log] => Automatic validation enabled.
            [var] => 1
        )

    [read_data5] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `Report`.`Date` AS `Report.Date`, `Report`.`STime` AS `Report.STime`, `Report`.`Name` AS `Report.Name`, `Report`.`Duration` AS `Report.Duration`, `Report`.`Account` AS `Report.Account`, `Report`.`APaid` AS `Report.APaid`, `Report`.`Voucher` AS `Report.Voucher` FROM `00_UCD_LessonReport` AS `Report` WHERE `Report`.`Date` >= '14/01/2019' AND `Report`.`Date` <= '14/01/2019' AND `Report`.`ILicense` = '071266767' GROUP BY `Report.Date`, `Report.STime` LIMIT 250;
                )

            [var] => Array
                (
                    [0] => Array
                        (
                            [Report] => Array
                                (
                                    [Date] => 14/01/2019
                                    [STime] => 08:00
                                    [Name] => Addison McEwan
                                    [Duration] => 60
                                    [Account] => Cash
                                    [APaid] => 70
                                    [Voucher] => 
                                )

                        )

                    [1] => Array
                        (
                            [Report] => Array
                                (
                                    [Date] => 14/01/2019
                                    [STime] => 10:15
                                    [Name] => Isaac Anderson
                                    [Duration] => 
                                    [Account] => K2D
                                    [APaid] => 
                                    [Voucher] => 
                                )

                        )

                    [2] => Array
                        (
                            [Report] => Array
                                (
                                    [Date] => 14/01/2019
                                    [STime] => 10:45
                                    [Name] => Isaac Anderson
                                    [Duration] => 60
                                    [Account] => Cash
                                    [APaid] => 65
                                    [Voucher] => 
                                )

                        )

                    [3] => Array
                        (
                            [Report] => Array
                                (
                                    [Date] => 14/01/2019
                                    [STime] => 13:30
                                    [Name] => Elizabeth Dresens
                                    [Duration] => 60
                                    [Account] => 
                                    [APaid] => 
                                    [Voucher] => 
                                )

                        )

                    [4] => Array
                        (
                            [Report] => Array
                                (
                                    [Date] => 14/01/2019
                                    [STime] => 15:00
                                    [Name] => Thomas  Crooke
                                    [Duration] => 60
                                    [Account] => Credit
                                    [APaid] => 66.95
                                    [Voucher] => 
                                )

                        )

                )

        )

)
healyhatman 20 Jan, 2019
Answer
OK Sorry

Data source:
{var:read_data5.[n].Report}

And then use just fieldname:Title (if you want a specific title for a column) or just leave it.
U Can Drive 20 Jan, 2019
Except the page remains frozen once the file has downloaded😟
healyhatman 20 Jan, 2019
Well yes once the file is downloaded it can't do anything else, that's the way web browsers work sorry. You need to put it in a separate event and display a link to the event (clicking it will just download, not change your page).
healyhatman 20 Jan, 2019
It's 1am here but if you search around I figured out a way to automatically call the event on load using javascript. On here somewhere.
U Can Drive 20 Jan, 2019
I've linked the event, but it doesn't carry the search parameters with it. (StartDate & EndDate) Is there a way to put that information in a url as I'm using a hyperlink.
healyhatman 20 Jan, 2019
Just add &startdate=......&enddate=.... To the url.
U Can Drive 20 Jan, 2019
Sorry bro, really appreciating your time and support here🙂

the url finishes with index.php?option=com_chronoforms6&chronoform=Report&StartDate=

How do I put a field entry into that?
U Can Drive 20 Jan, 2019
Aghh, I had tried that, it wasn't working. I'd put FinishDate instead of EndDate😟

That is all working perfectly, thank you, really appreciate it🙂
This topic is locked and no more replies can be posted.