Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Error when submitted in a Craft Preview #2082

Open
maxstrebel opened this issue Oct 7, 2024 · 4 comments
Open

JSON Error when submitted in a Craft Preview #2082

maxstrebel opened this issue Oct 7, 2024 · 4 comments

Comments

@maxstrebel
Copy link

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

  • Multi-page form: No
  • Submission Method: Ajax
  • Client-side Validation: No
  • Custom Form Templates: No

Craft CMS version

Craft Pro 4.11.5

Plugin version

2.1.28

Multi-site?

Yes

Additional context

No response

@engram-design
Copy link
Member

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
Copy link
Author

maxstrebel commented Oct 7, 2024

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
Copy link
Member

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
Copy link
Author

Thank you, would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants