GravityForms: tw-sack.min – Uncaught SyntaxError: Unexpected identifier tw-sack.min.js:1

Here is what the error looks like in the Chrome Debugger Console:

Uncaught SyntaxError: Unexpected identifier tw-sack.min.js:1

GravityForms:

If you’r getting a problem with editing forms in GravityForms, or perhaps trying to add fields, you can take a look at the source code and you’ll see what happens – an AJAX request is made, but twsack does not like the response which looks something like:

EndAddField({“id”: 1, “label”: “Hidden Field”, “adminLabel”: “”, “type”: “hidden
“, “isRequired”: false, “size”: “medium”, “errorMessage”: “”, “inputs”: null}, ”

  • Hidden : Field ID 1

    DeleteDuplicateEdit

  • “);m

    So the problem is actually that the response comes back with a `Content-type` of json, javascript, or html when it should be returned as `text/plain` – something like:

    Content-Type: text/html; charset=UTF-8

    To test, I edited the file `form_detail.php` and changed line 2178 (or rather inserted this line) – for gravity forms 1.7.5 (omit the line numbers):

    2178 header(‘Content-type: text/html; charset=utf-8’);
    2179 die(“EndAddField($field_json, \”$field_html\”);”);

    Next I am going to look into changing the .htaccess file for this system to see about editing the default content type which I think is causing the root of the error.

    **Update**

    Looks like the content type was a fix but it is not the solution – at least not for when adding fields.

    It looks like this is a problem when using GravityForms with Nginx and PHP with WordPress – or perhaps just something that could have been better coded in Gravity forms. The `$field_html` variable needs to be escaped with add_slashes – here is the fix with line numbers for the file `wp-content/plugins/gravityforms/form_detail.php`

    2177 $field_html = GFFormDisplay::get_field($field, “”, true);
    2178 echo “EndAddField($field_json, \””.addslashes($field_html).”\”);”;
    2179 die();

    Related Posts:

    • No Related Posts
    This entry was posted in Tech Tips and tagged , . Bookmark the permalink.

    3 Responses to GravityForms: tw-sack.min – Uncaught SyntaxError: Unexpected identifier tw-sack.min.js:1

    Leave a Reply

    Your email address will not be published. Required fields are marked *