verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
93 stars 69 forks source link

Snapshot data won't save on controller action before session exists #1860

Closed mijewe closed 1 month ago

mijewe commented 1 month ago

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

Craft CMS version

4.9.0

Plugin version

2.1.13

Multi-site?

Yes

Additional context

No response

engram-design commented 1 month ago

Fixed for the next release. To get this early, run composer require verbb/formie:"dev-craft-4 as 2.1.13".

mijewe commented 1 month ago

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.

engram-design commented 1 month ago

Updated in 2.1.14