Forums

Help on using CSV Export v2 [GH] action

Guidonzolo 05 Apr, 2013
Hello,
I've to export some data to CSV file.
I've build a form, with a MultiRecord Loader action (on the OnLoad event) and then, in the on Submit event, i've added the CSV Export v2 [GH] action. I've set the Data Path = Model ID of the MultiRecord. When clicking the Submit button I've no file download. I suppose it does not work!😟
Then i've added a new MultiRecord Loader in the on Submit event, with the same parameters of the first one, and now, when clicking the submit button, i can download the csv file.
Is it the right way for exporting the data when submitting the form?
Ok, another question. I've set the columns that must be exported with the "Column details" parameter, in the following format:
My Service=service
Full Cost=money
...
and so on.
I've noticed that, if the CSV Export v2 [GH] action gets its data from the Multirecord action (that is with Data Path = Model ID of the MultiRecord) then the file csv exports always all columns. If I set the CSV Export v2 [GH] action to get data from a table (that is Table=table name) it exports the right columns.
Is there any issue? What's wrong?
A last question....
The multirecord loader has the following "Where Statements":
<?php $user = &JFactory::getUser(); echo "cf_user_id = ".$user->id ?>
that is the query is filtered on the logged user.
Is there any way for set the CSV Export v2 [GH] action in the same way? I've tried but it does not work.

Thanks at all and sorry for my bad english
Guido Sabatini
GreyHead 06 Apr, 2013
Hi Guido,

If the DB Multi-Record Loader is in the On Load event and the CSV Export [GH] action is in the ON Submit event then they are completely separate and the CSV EXport action can't see the data from DB Multi Record Loader.

I'm not sure why you would want to link them? I think that you can get your data directly in the CSV Export action. I've never tried linking the two so don't know if that works or not.

The WHERE clause should work correctly in the CSV Export action. What MySQL query do you see if you add a Debugger action?

Bob
Guidonzolo 08 Apr, 2013
Hi GreyHead,
and thanks for your support.
I've tried to link them because of the CSV Export action does not accept my Where clause and i've seen that it has a Data Path property to link to a MultiRecord Action.
However, I've set the WHERE clause of the CSV Export action in the same way of the Multirecord but it does not work.
The clause is:
<?php $user = &JFactory::getUser();echo "cf_user_id = ".$user->id ?>
I've debugged the form: when submit (for exporting the data) the SQL query is without the Where clause. If I edit the CSV Export action, in the where clause there is only a part ofe the where clause: <?php $user = &JFactory::getUser();echo
I suppose that could be some bug where save the action after editing.
How can I do?
Thanks again
Guido Sabatini
GreyHead 08 Apr, 2013
Hi Guido,

Ah, I think I see the problem. Please try the WHERE clause without using double quotes ", ChronoForms doesn't like them. This should work OK:
<?php $user =& JFactory::getUser(); echo '`cf_user_id` = '.$user->id; ?>

Otherwise you can build the WHERE clause in a Custom Code action, add it to the $form->data array like this:
<?php
$user =& JFactory::getUser();
echo '`cf_user_id` = '.$user->id; ?>
$form->data['where'] = "`cf_user_id` = '{$user->id}' ";
?>

Then put {where} in the CSV Export [GH] WHERE box.

This approach is useful for more complicated WHERE clauses.

Bob
Guidonzolo 09 Apr, 2013
Thanks GreyHead,
your first solution doesn't work but the second one ({where}....) is right.
Thanks again.

Guido Sabatini
GreyHead 09 Apr, 2013
Hi Guido,

That's good to know, thank you.

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