Snapshot data won't save on controller action before session exists
Describe the bug
I've got a custom controller action that loads a template, loads a Formie form with it, and sets some custom snapshotData on the form.
$form->setSnapshotData('extraData', $extraData);
return $this->renderTemplate('template.twig', [ 'form' => $form ]);
If all cookies and session data are cleared, on the first page load the snapshot data will be empty.
On the second page load, the extraData will have been set correctly.
This is because the setSnapshotData function checks Session::exists(), which returns false on this first page load.
My temporary low tech fix for this is to set the snapshot data in the template
{% do form.setSnapshotData('extraData', extraData) %}
{{ craft.formie.renderForm(form) }}
but this isn't ideal and wouldn't work for every use case.
Steps to reproduce
as above
Form settings
- Multi-page form: No
- Submission Method: Page reload
- Client-side Validation: Yes
- Custom Form Templates: No
Craft CMS version
4.9.0
Plugin version
2.1.13
Multi-site?
Yes
Additional context
No response
Fixed for the next release. To get this early, run composer require verbb/formie:"dev-craft-4 as 2.1.13".
Thanks!
FYI this also appears to have fixed a similar problem I was looking into, where my PHP-edited Webhook Integration wasn't firing on first load, presumably for the same reason as not having a session to save into.
Updated in 2.1.14