2

I've added a custom toolbar button to export the items from a custom component as a CSV.

The CSV is getting exported correctly but my custom task is then being triggered when navigating the component in the CMS i.e. clicking on any pagination link exports the CSV again.

I can see that the task is stored in a hidden value, and that is why my custom toolbar is being triggered.

<input type="hidden" name="task" value="individuals.exportCsv">

Firstly, how do I go about resolving this issue? Secondly, I've included the export code below, is this the best approach?

// output headers so that the file is downloaded rather than displayed
header("Content-Type: text/csv; charset=utf-8");
header("Content-Disposition: attachment; filename=individuals.csv");

// create a file pointer connected to the output stream
$output = fopen("php://output", "w");

// outputh the column headings
fputcsv($output, array("id", "first_name", "last_name", "job_title", "address_1", "address_2", "postcode", "email", "mobile", "direct_line"), "\t");

foreach($items as $item)
{
    fputcsv($output, (array) $item, "\t");
}

fpassthru($output);

jexit();
  • You should provide a full code for exporting (including the controller code). Other thing is that you should provide the code that is creating the toolbar button (this is mostly what cause the problem). – Artur Stępień May 13 '17 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.