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}, "
<li id='field_1' class='selectable gfield     gform_hidden' ><div class='gfield_
admin_icons'><div class='gfield_admin_header_title'>Hidden : Field ID 1</div><a class='field_delete_icon' id='gfield_delete_1' title='click to delete this field
' rel='nofollow' href='#' onclick='StartDeleteField(this); return false;'>Delete</a><a class='f
ield_duplicate_icon' id='gfield_duplicate_1' title='click to duplicate this fiel
d' rel='nofollow' href='#' onclick='StartDuplicateField(this); return false;'>Duplicate</a><a c
lass='field_edit_icon edit_icon_collapsed' title='click to edit this field'>Edit
</a></div><label class='gfield_label' for='input_1'>Hidden Field</label><input p
laceholder="Hidden Field"  name='input_1' id='input_1' type='text'  value='' dis
abled='disabled'/></li>");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 *