Accessing Typeform form data using Typeform API and PHP

The last type I wrote a tutorial in regards to using a web-based survey platform, it was how to access Wufoo form data.

In that tutorial, I said “Before we know it, Thanksgiving and Christmas will be here and it’ll be the end of the year.”

Well, Thanksgiving down, and Christmas and the end of the year are near.

To follow up the Wufoo API tutorial, there have been many requests for Typeform.

Unlike CCB forms, Typeform allows for a customized design and experience that is easy to use and responsive across multiple device platforms.

In addition, Typeform offers an API to access submitted form data.

So yes, you can customize the Typeform experience to match your church’s website’s look and feel, yet capture data in CCB too.

Although I didn’t cover the full integration to CCB with the Wufoo form, I’m doing so today with the Typeform tutorial.

Let’s get started with today’s tutorial

Your Typeform Account and Form

For starters, if you haven’t already created a Typeform account and your first form, please do so now. Make sure your from has the following fields:

  • Full Name
  • Email
  • Phone

We’ll use the Typeform API to access your form data. Go ahead and complete the form a few times to ensure you have data to access.

Setting Typeform API and PHP variables

If you plan on integrating today’s tutorial with CCB data, then I recommend starting by including the normal file inclusions and comments as we have in previous tutorials.

Next, using the Typeform API documentation, define the following variables:

  • tfApiKey – set this variable equal to the Typeform API key
  • tfUID – set this variable equal to the Typeform form Id
  • tfBaseAPIUrl – set this variable equal to the Typeform base url for forms

Time to make Typeform API call using PHP

After setup credentials have been successfully defined, it’s time to create the target url that will be passed to the Typeform function to make the API call.

Create a targetUrl variable and set the value to look like the code below:

Note: The Typeform API can return data using json or xml. Read the Typeform API for more details.

Next, create a responseArr variable and set it equal to the Typeform function, passing get as first argument and the targetUrl as the second argument.

I’ll cover the Typeform function details here shortly.

Parsing Typeform API and PHP response

Next, set a response variable, and set it to use PHP’s built-in json_decode method, setting the first argument to pass the previous responseData variable and the second argument to true.

Next, set an empty displayData variable.

Because Typeform API returns a status code when an API call is made, set an if statement to check the response variable’s http_status for being equal to 200.

For now, we’ll focus on the if statement being successful, but you could easily add additional error validation rules if you would like.

Once inside the if statement, then create an ids variable and set it to an empty array.

Next, create a foreach statement to traverse each Typeform question, passing the response variable questions element. Within the foreach statement, set the ids variable to add each questions respective id to the ids array. Then, close the foreach statement.

Next, create another foreach statement to traverse each Typeform response. Within the foreach statement, you can now access each responses answers by placing the ids array values within each answer array as shown below:

Next, it’s time to check to see whether the person submitting the form has a valid CCB profile.

To do so, create a userExist variable and set it equal to the checkUserExistence function, passing the second answer array index as the first argument and the third answer array index as the second argument.

Now that the userExist variable exists, create an if statement that checks the value of userExist variable. If the value of userExist variable is less than 1, then there is not a valid CCB profile for the person and a profile will need to be created.

To create the profile, set the displayData variable to concatenate and be equal to createPerson function person, passing all three arrays (i.e., full name, email and phone) as function arguments in their respective order.

Next, close the foreach statement and the if statement, and then we finally echo the displayData variable.

Put it together and test away

Yes, you’re ready to test your Typeform API prowess and gain a quite a trove of manual migration hours back.

Save your file and open it via a web browser. Here’s what your code should look like:

You now have a fully integrated Typeform to CCB tutorial that allows for you to customize the user experience of your survey form anyway you would like, yet collect your data in CCB.

Typeform, checkUserExistence and createPerson Functions

If you’re integrating the following functions with CCB, then don’t forget to include the functions code below in the general.php file.


Please comment if this tutorial has helped you.