ideas
ideas copied to clipboard
Custom form submission exporters
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.
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.
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?
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/.
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.
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?
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.
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)?
Just got the use case for Excel Export as well.