The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] jQuery 1.4.*, Contact Form 7 v2.2.2 and JSON (and Tracking with Analytics) (4 posts)

  1. blablu
    Posted 6 years ago #

    Okay.. I had some serious trouble with my Contact Form 7 implementation.

    First I updated the jQuery library to 1.4 (I'm not 100% sure but WP is using 1.3 atm).

    This causes the main problem. Since 1.4 jQuery doesn't support "invalid" JSON syntax (use http://www.jsonlint.com/ to test if yours valid) even if its valid javascript, pretty annoying!! (I found this reason after a couple hours of testing, first I tought my tracking code "Additional Settings" causes the problem).

    Okay I was running Contact Form 7 2.1.1 on my system. I upgraded to 2.1.2 (see changelog: "Incorrect JSON syntax causing conflict with jQuery 1.4 has been fixed.") and I got no longer JSON errors.

    So I reentered my tracking code and again I got JSON errors. Finanlly I found out that JSON implementation of Contact Form is still not working properly. I replaced the function wpcf7_json in controller.php on line 103 with the PHP json encoder (since version 5.2) and voila: it works! With my analtics code!

    I hope this report helps other people to solve their problems faster.


  2. jasontremblay
    Posted 6 years ago #

    Thank you SO much for posting this! My form's ajax has been silently failing for hours and I didn't even think to check for valid AJAX return values. Viola indeed :)

  3. binlid
    Posted 6 years ago #

    I've got a backward-compatible fix for WPCF7 v2.2, check out this patch:


    It works with jQuery 1.3.2 and 1.4.2, and doesn't break if the server isn't running at least 5.2.

    The fix uses json_encode if it's available, and strips the slashes from the extra settings on save, so jQuery 1.4.2 has validating JSON.

  4. cnev
    Posted 6 years ago #

    Thanks for that patch binlid, solved my problem (once I'd worked out how to apply it, which was obvious, in retrospect ;)

    For anyone who has switched to the newer async Google Analytics tags that go in the header of the page, here's what I put in my WPCF7 additional settings:

    on_sent_ok:"_gaq.push(['_trackPageview', '/contact_form_sent']);"

    Of course, put anything you like in place of: /contact_form_sent

    I'm using virtual pageviews like this because events can't be turned into goals in Analytics.

Topic Closed

This topic has been closed to new replies.

About this Topic