Export Types

Extend Freeform Exporting capabilities by adding your own export types:

Registering Custom Export Types

Use this event to attach your own export types.

First, create your own export type, which extends the Export Interface:

<?php

namespace My\Exporter;

use Solspace\Freeform\Library\Export\ExportInterface;
use Solspace\Freeform\Library\Composer\Components\Form;

class CustomExport implements ExportInterface
{
    private $submissionData;

    public function __construct(Form $form, array $submissionData)
    {
        $this->submissionData = $submissionData;
    }

    public static function getLabel(): string
    {
        return 'Custom Export';
    }

    public function getMimeType(): string
    {
        return 'text/html';
    }

    public function getFileExtension(): string
    {
        return 'html';
    }

    public function export()
    {
        return '<html><body><pre>'.json_encode($this->submissionData).'</pre></body></html>';
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

Then register your exporter:

use Solspace\Freeform\Services\ExportProfilesService;
use Solspace\Freeform\Events\ExportProfiles\RegisterExporterEvent;
use My\Exporter\CustomExport;

Event::on(
  ExportProfilesService::class,
  ExportProfilesService::EVENT_REGISTER_EXPORTER,
  function (RegisterExporterEvent $event) {
    $event->addExporter(
      'custom_export', 
      CustomExport::class
    );
  }
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14

You should now see your custom export type available in the export profiles view and in the quick export pop-up.

Last Updated: 3/16/2022, 3:45:13 PM