verbb / formie

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

JSON Error when submitted in a Craft Preview #2082

Open maxstrebel opened 1 month ago

maxstrebel commented 1 month ago

Describe the bug

We have a form that will throw an error: Unable to parse response 'Syntax Error: Unexpected Token "<",...' when we fill it out in a page that is a Craft CMS preview (URL only has the token parameter ?x-craft-preview=).

image

Steps to reproduce

  1. Create a form (with Text fields, an email field and an agree field)
  2. Open a page in a Craft Preview Link with token
  3. Submit form
  4. Get error Unable to parse response 'Syntax Error: Unexpected Token "<",...'

Form settings

Craft CMS version

Craft Pro 4.11.5

Plugin version

2.1.28

Multi-site?

Yes

Additional context

No response

engram-design commented 1 month ago

That's correct behaviour - at least for the moment. The reason is because it's trying to get a response for a form submission for a page that's in live preview, and it'll fail. If you inspect the network request, you'll see that it's returning the HTML of the page you're previewing, rather than a JSON response.

Basically - forms don't really work in live preview.

maxstrebel commented 1 month ago

Thanks for the quick reply. As this also happens if you have preview link (outside of live preview, if you click on "View"), I would like to suggest a more descriptive error message (something linke "This form cannot be submitted from a preview link").

It took me quite some time to understand why the form is not working. And I do not see a obvious reason why the form should not be working in a preview link (not talking about live preview).

engram-design commented 1 month ago

Yes, preview and live preview will do the same thing here. I'm looking into options for this, including an error message when submitting the form, checking for a preview request, but ideally I'd like to make this work in preview.

maxstrebel commented 1 month ago

Thank you, would be great.