ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Custom form submission exporters

Open aerni opened this issue 3 years ago • 6 comments

It would be nice if we could override or add new form submission exporters on a per form level. I need to add some computed fields when the form is exported.

Example: I've got an event sign-up form. This form is shared for a number of different events. To identify for which event a user signed up for, I'm passing the event ID using a hidden field to the form submission. When exporting the form submissions, I'd like to grab the title and date of each event using its ID. The title and date will then be added to the export, and the ID will be removed.

aerni avatar Jul 28 '22 16:07 aerni

It might be possible to add the computed data to the submission using a FormSubmitted listener. But I don't essentially need the event data on the submission but want to grab it in real-time when exporting the submissions.

aerni avatar Jul 28 '22 16:07 aerni

I need to add some computed fields when the form is exported.

Maybe I can add support for computed values to forms to this PR https://github.com/statamic/cms/pull/6179, something like...

Statamic\Facades\Form::computed('contact', 'some_field', function ($submission, $value) {
    // ...
});

As long as it works with current exporter, would that work for you?

jesseleite avatar Jul 28 '22 20:07 jesseleite

That could work for this use case, yes. Really neat PR btw! Custom exporters would still be nice. For instance, if you want to export to Excel with https://laravel-excel.com/.

aerni avatar Jul 28 '22 20:07 aerni

For sure, will leave this issue open for that reason. We'll probably be bringing computed fields to other things as well. I'll see how easy it is to add to forms, and maybe we can squeeze into that PR for now.

jesseleite avatar Jul 28 '22 21:07 jesseleite

There is another common reason for custom exporters. When downloading the CSV, it usually makes sense to have the field titles as the header rather than the field handle. This is much more user-friendly. This could be added to the current CSV exporter as an option or changed to be the field titles altogether. Happy to contribute to this. What do you think?

aerni avatar Jul 30 '22 17:07 aerni

Maybe we add to config/forms.php for either:

  • Changing csv header from field handle to field label
  • Changing to a custom exporter altogether (should also be able to accept config params from the config file)

Or maybe both, see what @jasonvarga thinks.

jesseleite avatar Aug 01 '22 16:08 jesseleite

Not 100% relevant to the original issue, but as @jesseleite mentioned this, is there an easy/existing way with new Computed fields being introduced to have computed fields displayed on the individual form Submission too (not just on Collection/User)?

artemverbo avatar Nov 09 '22 23:11 artemverbo

Just got the use case for Excel Export as well.

marcorieser avatar Aug 29 '23 15:08 marcorieser