surveyjs / surveyjs-wordpress

Example of integration SurveyJS: Survey Library and Survey Creator into WordPress
https://wordpress.org/plugins/surveyjs/
36 stars 18 forks source link

Survey entries don't show (JSON.parse: bad escaped character) #47

Closed kuchengrab closed 4 months ago

kuchengrab commented 4 months ago

Hi, when trying to show the results of a survey in the Wordpress/SurveyJS backend, it only shows the title and a blank page. The browser's error log shows the following message:

Uncaught SyntaxError: JSON.parse: bad escaped character at line 1 column 280 of the JSON data
    data https://example.com/wp-admin/admin.php?page=surveyjs_results&id=5&name=RaS2024_final_de-en:444
    <anonymous> https://example.com/wp-admin/admin.php?page=surveyjs_results&id=5&name=RaS2024_final_de-en:443
[admin.php:444:41](https://example.com/wp-admin/admin.php?page=surveyjs_results&id=5&name=RaS2024_final_de-en)

Fortunately, I was able to locate the wp_sjs_results table, so I can see the raw JSON data. But I'd like to be able to export the entries as CSV. Any hints what the "bad escaped character" could be or how to look for it? (I have no clue what "column 280" could mean).

JaneSjs commented 4 months ago

Hello @kuchengrab, The "Uncaught SyntaxError: JSON.parse: bad escaped character at line 1 column 280 of the JSON data," error indicates that there is an issue with the format of the JSON object which is passed to the JSON.parse() function.

Unfortunately, it is difficult to determine the cause of the issue using the provided survey form. We would be in a better position to research the issue if you could share an example of a problematic survey.data object. You may submit a ticket at Help Desk and share relevant data for research.

Thank you

kuchengrab commented 4 months ago

Thanks @JaneSjs for your reply. I sent a few lines of the data on the ticket number T18141.

kuchengrab commented 4 months ago

Ok I did some testing myself and found one problematic JSON data line: {\"name\":\"F. \",\"email\":\"example@gmail.com\",\"Einverstaendnis1\":false,\"newsletter\":true,\"ini\":\"ExampleIni\",\"anreise\":\"nein berlin\",\"biete-schlafplatz\":false,\"kinder\":false,\"gesamtes-forum\":\"Ja\",\"unvertr\":false,\"essen-sonst\":\"wird bestimmt lecker &lt;3\&quot;,\&quot;anmerkungen-sonstige\&quot;:\&quot;Wäre sehr gerne dabei &lt;3\&quot;}

while it should be: {\"name\":\"F. \",\"email\":\"example@gmail.com\",\"Einverstaendnis1\":false,\"newsletter\":true,\"ini\":\"ExampleIni\",\"anreise\":\"nein berlin\",\"biete-schlafplatz\":false,\"kinder\":false,\"gesamtes-forum\":\"Ja\",\"unvertr\":false,\"essen-sonst\":\"wird bestimmt lecker <3\",\"anmerkungen-sonstige\":\"Wäre sehr gerne dabei <3\"}

When I change the database entry manually, the error is gone and the table is rendered correctly. 🥳

So the problem seems to be that "<" triggers transformation to html code but also subsequent double quotation marks " which is of course unintended.

kuchengrab commented 4 months ago

This is not related to the bug anymore, but I have a follow-up question (if it makes sense, I can also repost it as a new issue/suggestion): Is it possible to order the entries by timestamp (or database id)? Alphabetic order of any field doesn't make much sense in our case (to track new registrations and send them confirmation emails). Looks like I would need to add the timestamp as a field in the survey or something to achieve that?

dmitry-kurmanov commented 4 months ago

We fixed the problem via the https://github.com/surveyjs/surveyjs-wordpress/pull/49. The fix is already available.