This may be a no-brainer to some, but I couldn’t find a clear answer to this through Googling, so here we go.

We have an upcoming event on campus that brought up a seemingly simple request: have a form available to fill out online and display a live count of form submissions on computers and/or TV screens in the Campus Center. (I drank the Wufoo kool-aid long ago, so when I heard “online form”, that’s where my head went. We could have also written some quick custom PHP/MySQL to do the job, but that’s no fun.)

The question was how to get a count of the form submissions out of Wufoo.

There are likely many ways to accomplish this (based on the form’s RSS feed, etc.) but I took it as an opportunity to dig into the Wufoo API – something that frightened me. See, I have a confession to make: HTML and CSS are my friend. PHP? We get along kind of okay, but anything the least bit complicated makes me run away shrieking. API’s? No clue. Scares the crap out of me.

Not anymore. This was easy. And it was pretty much all there in the Wufoo documentation.

The Code

<?php
$curl = curl_init('https://{your-wufoo-account}.wufoo.com/api/v3/forms/{hash-for-your-form}/entries/count.xml');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, '{your-api-key}:footastic');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Wufoo Sample Code');

$response = curl_exec($curl);
$resultStatus = curl_getinfo($curl);

if($resultStatus['http_code'] == 200) {
echo $response;
} else {
echo 'Call Failed '.print_r($resultStatus);
}
?>

Explanation

Let’s dig just a tad deeper into the pieces you need to fill in and what’s going on here.

1. {your-wufoo-account}
The URL prefix for your account.

2. {hash-for-your-form} and {your-api-key}
These can both be found by going to the “Forms” tab in the Wufoo admin area and clicking “Code” underneath the name of your form. On the next screen, click “API Information” at the top right of the screen. Finally, on that page you will find your unique API key and form hash.

3. What’s Happening
The magic is simply in the XML URL in the very first line of code. By ending the URL with /entries/count.xml, we’re telling Wufoo to return the count of entries. (I told you this was easy.) In our case, we’re storing that entry count in the $response variable and then simply printing that count on screen with the PHP echo command. At this point you could easily use that count in any number of calculations, as a basis for some other looping or paging code, etc.

Resources

Further documentation can be found on Wufoo’s support site:

Screenshots of this code in action coming soon!