public function download($form_key)
 {
     //In single_pages, do not prepend "action_" (unlike blocks)
     header('Content-type: text/csv');
     header('Content-Disposition: attachment; filename="' . $form_key . '_form_submissions.csv"');
     $fields = CustomContactForm::getFieldNamesAndLabelsForDashboardReport($form_key);
     $submissions = CustomContactForm::getSubmissionsForDashboardExport($form_key);
     //heading row
     echo '"' . t('Submitted At') . '","' . t('From Page') . '","' . t('IP Address') . '","' . implode('","', $fields) . '"' . "\r\n";
     //data rows
     foreach ($submissions as $submission) {
         $quoted_values = array('"' . $submission['submitted_at'] . '"', '"' . str_replace('"', '""', $submission['page_title']) . '"', '"' . $submission['ip_address'] . '"');
         foreach ($fields as $name => $label) {
             $value = $submission['fields'][$name];
             //convert all CR and LF to CRLF for excel
             $value = str_replace("\r\n", "\n", $value);
             $value = str_replace("\r", "\n", $value);
             $value = str_replace("\n", "\r\n", $value);
             //escape quotes
             $value = str_replace('"', '""', $value);
             //surround value in quotes
             $value = '"' . $value . '"';
             $quoted_values[] = $value;
         }
         echo implode(',', $quoted_values) . "\r\n";
         //output this row
     }
     exit;
 }
 public function download()
 {
     //In single_pages, do not prepend "action_" (unlike blocks)
     header('Content-type: text/csv');
     header('Content-Disposition: attachment; filename="contact_form_submissions.csv"');
     $fields = CustomContactForm::getFieldNamesAndLabelsForDashboardReport();
     $submissions = CustomContactForm::getSubmissionsForDashboardReport();
     //heading row
     echo t('Submitted At') . ',' . t('IP Address') . ',' . implode(',', $fields) . "\n";
     //data rows
     foreach ($submissions as $submission) {
         $quoted_values = array('"' . $submission['submitted_at'] . '"', '"' . $submission['ip_address'] . '"');
         foreach ($fields as $name => $label) {
             $quoted_values[] = '"' . str_replace('"', '""', $submission['fields'][$name]) . '"';
         }
         echo implode(',', $quoted_values) . "\n";
     }
     exit;
 }