Accessing User Defined Fields Via Individual CCB Profile

It’s been a while since I’ve had a chance to post tutorial.  Please accept my sincerest apologies for having kept you waiting and anticipating the next tutorial.

Thanking God for a good number of projects, I’ve been quite busy consulting and helping a number of churches and companies with various software and application development projects.

Nevertheless, I received a request via comments about how to access user defined fields when using the CCB to return an individual profile (see below).

How to backup your CCB account

I won’t cover how to execute the the API call to retrieve or search for an individual CCB API call (see below).

Creating a reusable function for CCB API calls

Feel free to use the CCB API call instead of the hardcoded XML response I’ll use in this tutorial today. Let’s get started.

In lieu of making the CCB API to return an individual CCB profile, I’m creating my own XML content that resembles the XML Response return when executing CCB API call.

To start this tutorial, create a xmlContent variable with the following XML string content as shown below:

For more information on creating and parsing XML strings using PHP and SimpleXML, click here.

Once the xmlContent variable has been created with XML string content, define a xml variable.

Set the value of the xml variable to instantiate a new SimpleXMLElement object, passing it the xmlContent variable.

The following section will appear quite familiar due to it being in most of the tutorials created.

Now we’re ready to parse the XML response example using PHP’s built-in XPATH query method.

Define a nodes variable and set it’s value to the xml variable XPATH query expression of the following: //individuals/individual.

Now it’s time to iterate the XML response for each individual record. In this example, there is only one individual record.

However, you could have multiple individual records based on the type of CCB API call executed.

To iterate through each individual record, create a foreach statement, passing it the nodes variable as node variable.

Within the foreach statement, define a procdata variable. This variable is used to validate the existence of user defined pulldown fields.

Set the procdata variable to the following:

Now, create an if statement using the procdata variable. Do this to ensure that user defined pulldown fields exist before continue to access user defined pulldown fields.

Within the if statement, create another foreach statement, passing to it procdata as data variable, to iterate through each user defined pulldown fields.

Within this second foreach statement, you’re now ready to echo each respective user defined pulldown field’s label (as shown below).

Close the foreach, if and foreach statements, and you’re ready to piece everything together for a quick code test.

Below is what your code should look like:

Remember, you can swap the static html code and use a dynamic CCB API call instead (recommended).

Save your file and test the results via a web browser.

Happy coding and development, and that’s all for today. See you next week.

Please comment if this tutorial has helped you.