Forums

Export to csv in CF v5

Chickadee9 02 Jan, 2015
First, thanks for a great product. I've been able to create a form and save to my database. I have also been able to use the Export to csv CF v5 action to export all columns and just specified columns. I can't figure out how to export only certain rows based on a query. I know how to write the SQL query, I just can't find anything that tells me where to put the code. I found this how-to by Greyhead (http://greyhead.net/how-to-docs/cfv4-csv-export-gh-action) about CSV Export v2 [GH], but can I install and use this in CF v5? If not, is there an example of what I need to do? I'm a real newbie at PHP & HTML. I've been trying to find the code behind the csv export action (I thought it might help me understand what is happening), but all I see when I click the Code tab in form manager seems to be basic form code. Thanks so much for your help - Chronoforms and Joomla have really helped me get my data input form up and running!
GreyHead 02 Jan, 2015
Hi Chickadee9,

For some reason that I don't know the CFv5 CSV EXport action doesn't have a WHERE box. You can get round this by using a DB Read action to load the results, then export them with the Data Path setting in the CSV EXport action.

If this is an Admin only export then you can use the MijoSQL extension to do the same things and more.

Bob
Chickadee9 02 Jan, 2015
Thanks for the quick reply, Bob. I'll try the DB Read action solution. I'll also look at the MijoSQL extension.

Is there a way to see the code behind the actions? I thought seeing it might help me understand php better. I'm struggling with understanding how custom code works with/overrides the default code. I'm also going to have to update the table after exporting. I found another forum post where how to do this is described, but I'm still confused. When you have asked other questioners for their code, are you just asking for custom code they have written? Also, I know the Chronoforms book is not applicable to CF v5 in many areas, but do you think it would still be helpful to me, or would it just confuse me more?
Thank you for being patient with a beginner. I've been in IT in the corporate world for decades, but this web stuff is a whole new universe for me :?
GreyHead 03 Jan, 2015
Hi Chikadee,

You can see the code in the actions by opening the action files in the /administrator/components/com_chronoforms5/chronoforms/actions folder with a text editor - but I doubt that would be very helpful to you unless you already know your way around php.

Most often what us posted here is PHP from a Custom Code action.

I'm sorry to say it but I'm doubtful that the book is any longer much use to you. The ideas there are still valid but changes in the ChronoForms layout and the way that Joomla works make it harder to re-interpret.

What exactly do you need to do?

Bob
Chickadee9 03 Jan, 2015
Hi Bob. I'm definitely struggling with the lack of documentation - I'm used to having a bookshelf full of manuals! But these forums/FAQs and your help have been great. I'm building a Course Submission form for our local community college senior ed program. Users can submit info on a course they'd like to teach. The form is working and saves successfully to a mysql table. I have a hidden field in the table called exported_ind that I set to 'N' when a record is added. I've built another form that will allow us to export selected fields into csv. The export to csv action works fine but returns all records. I want to return only records where the exported_ind = 'N', and then set the exported ind in those records to 'Y' after the export. As you suggested, I added the DB Read action, but can't figure out how to refer to the results of the read in the Csv Export Data Path setting. I don't see anything in the DB Read that allows me to save the data so I can point to it in the Data Path setting. Does it go in the form data fields? If so, how do I refer to it? I added a debug action but don't see anything. Where do I see the debug results? Do I have it in the right place (see attached)? I also tried putting it after the export to csv.
And I haven't tried this part yet, but I assume I'll have to add some custom code to the 'On Submit' event, probably after the export to csv, to update the exported_inds? Is there a way to do a conditional db update, like this sql command?
update CourseSubmit set exported ind = 'Y' where exported ind = 'N';
Or, failing that, is there a way to just set all exported_inds to 'Y'?
Thanks again for all your help
Chickadee9 03 Jan, 2015
Hi again, Bob. Some more info to add to what I just posted.
This export form has nothing but some descriptive text and a Submit button. Do I have to add all the data fields as hidden fields for the DB Read action to work? If so, I still don't know where to find the data path. In another forum question you said this:

"The 'Data Path' refers to the ChronoForms $form->data array where the working data is kept. For example, if the data you want to export is in the $form->data['GSheet'] array then you'd put GSheet in the Data path box (which is the default value)."

I can't find anything like $form->data, even in the original course submit form that has plenty of data fields. BTW, I set up the DB Read to be Multi-read = Yes. I assume the $form->data array can hold multiple records?

Also, I found the php code for the actions. You're right, it is a bit overwhelming, but I find it helps me understand syntax etc if I have an example to look at. Don't worry - I have no plans to change any of it :-)
Chickadee9 05 Jan, 2015
Hi Bob - Good news! I found another forum entry that described what to use as the data path. I have to say it's not obvious that Model ID from the DB Read is what you use... I realized as well that I could create a MySql view to format my data, then reference that in the DB Read action. It works great.
Also, another of your posts about saving multiple checkbox entries into separate fields was very helpful. And I got Debug to work while I was working on that. Maybe what I was doing before didn't generate any debug info.
Now all I have to do is update the table after the export. I was thinking of calling a stored procedure rather than try to do the update from chronoforms. Would I put the call to the procedure in custom code after the export action? (I found a forum post about calling stored procedures too)

Thanks
Max_admin 11 Jan, 2015
Hi Chikadee,

Regarding your last question, you can run any code you want in a custom code action after the export, I didn't try to run a stored procedure myself before though.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.