Chasing Checkbox Support

For the past couple of days I have continued to look at the problem I wrote about with Google Forms and Checkboxes with PHP 5.4 and PHP 5.5.  It turns out, that it really isn’t PHP version related, at least I don’t think so.  It is WordPress related as near as I can tell.

As I’ve written before, I love VMware Workstation as it allows you to create virtual machines for very specific purposes, use them as long as needed, then put them away until needed again.

I created an Unbuntu VM to play with Ruby on Rails a couple months ago so I decided to check what version of PHP it had running.  Lo and behold, it had PHP 5.5.x running so it was a good platform to further test potential solutions for my checkbox problem.  My Windows environment is running PHP 5.3.3 and is still running WordPress 3.6.1 (don’t ask why but it proved to be very useful that it was).

I quickly set up WordPress 3.8 on Ubuntu and sure enough, submitting the form failed.  The exact same plugin code on my Windows VM submitted correctly.  I continued to dig through my code and eventually into WordPress itself trying to see what was different.

I eventually started looking at the source to wp_remote_post() and decided to identify which transport was being used.  On Windows WordPress was using cURL but on Ubuntu it was using Streams.  Ah-ha.  Since the WordPress HTTP API abstracts the details of the transports away from the application, it shouldn’t matter but it seems to.  I continued digging.

Using an advanced feature of WordPress Google Form to control transports, I disabled the cURL transport on the Windows machine and much to my surprise, the form still submitted correctly.  Now this is odd.  So I then installed cURL on Ubuntu and the form submitted correctly.  The good news is there at least appears to be a solution although I’d prefer to not have cURL be a requirement.

Now what was different?  I started looking into WordPress’ class-http.php file (which defines the WP_Http class) and noticed that the file on Windows was very different than the file on Ubuntu.  Looks like something changed between 3.6.1 and 3.8.1.

I decided to download the 3.6.1 and 3.7.1 releases from the WordPress archive and do some tests on Ubuntu where it is trivial to switch between WordPress releases.

To add a little more information, I did some testing with older versions of WordPress in combination with the http_api_transports to force a specific transport (‘streams’, ‘fsockopen’, and ‘curl’).  I found the following results:

WordPress 3.6.1 WordPress 3.7.1 WordPress 3.8.1
cURL Success Success Success
fsockopen Success Fail Fail
streams Success Fail Fail

Something clearly changed with the streams and fsockopen transports between 3.6.1 and 3.7.1.  A diff of the class-http.php file shows the change was substantial as the files are significantly different.

At this point I have concluded that my plugin will only work with sites where cURL is available.  I will probably release a version which displays a warning on the Dashboard if cURL is not available and that usage of the plugin is not recommended.

4 thoughts on “Chasing Checkbox Support

  1. Sorry to drum up an old post, but I’ve run across the checkbox issue and was curious if you’ve found any workarounds in the time since. I am not getting the cURL notification on my install, which leads me to believe things are ok – but the checkboxes are not submitting to Google. Thanks for any information you can provide!

    • Have you verified you do not have any Javascript errors when the page loads? A Javascript error may prevent the plugins jQuery script which “fixes” checkboxes so they’re compatible between WordPress (PHP) and Google Forms (Python) from running. If this jQuery script doesn’t run your checkboxes will never submit correctly so that is where I would look first.

  2. Hello, we have cURL in our webserver enabled, there is no Javascript errors, our checkboxes shows in website, but when someone is filling google form in our website and for example checks 5 options out of 10, only 1 is visible in Google form results spreadsheet.
    If we will google form directly it shows all selected options: option1, option 4. option5, etc.

    We are using WordPress 4.x, and Google Forms 0.91

    Have you faced this problem which checkboxes?

    Thanks.

    • Yes, I have seen this problem before and every single time it has been due to a Javascript error or something else which prevents the Google Forms jQuery script from running. WordPress is written in PHP and Google Forms (on the Google side) is written in Python and the two languages handle checkboxes differently. The jQuery script which runs once the page which contains the form is finished loading, makes a slight modification to the checkboxes to allow them to work with PHP on the WordPress side. WordPress in turn submits all of the data to Google using the WordPress HTTP API.

      If you are 100% sure you don’t have any Javascript errors when the page loads, the next thing to do is to put Google Forms in debug mode. In debug mode the plugin captures all sorts of state data at various points in the submission process and puts it in DIV containers that you can look at on your web site. It allows tracking progress through the plugin processing. You don’t want to leave debug on as it will likely confuse your end users.

      For testing purposes, I would create a new form which only has some checkboxes on it and if you want, I can put the same form on my site and see if it works correctly. You can also try temporarily disabling all plugins except Google Forms to ensure another plugin isn’t preventing the jQuery script from executing.

Leave a Reply