Published
Friday, March 11, 2016 - 06:06
Written by

Our customer Werk met Zin (Network of job coaches in Flanders) has a Wordpress site and uses CiviCRM to manage their relations and cases. On their Wordpress site they allow users to register for some events, which they solve with the civicrm event info and registration pages.

However, they also allow an individual to request the start of individual job coaching with a form. This should end up in CiviCRM as a special activity with the fields on the website form as custom data. And the Wordpress website is on another server, although that would not make such a big difference. Anyway, we (as in CiviCooP) developed a specific solution that takes the data from the Wordpress website on server A and sends it to CiviCRM on server B. The solution has a Wordpress part and a CiviCRM part.

The Wordpress plugin

This plugin can be found at https://wordpress.org/plugins/contact-form-7-civicrm-integration/ and works with the Contact Form 7 plugin. This plugin adds integration for CiviCRM to contact form 7. With this plugin it is possible to submit a contact form to an external CiviCRM. The plugin allows you to set the configuration items for the CiviCRM REST api (server, api key and site key)

Per contact form you could enable CiviCRM integration. The submission of the contact form is then submitted to the CiviCRM REST api. That is why you should also enter an CiviCRM entity and an CiviCRM action. The data in the form should then match the data for the api. E.g. if you push a first_name to the Contact api your field in the form should alsobe called first_name.

The CiviCRM extension

The CiviCRM extension has some stuff to create configuration items (activity types, option groups, option values, custom groups and custom fields are created or updated automatically by a scheduled job in the extension).

There is also an API WpCivi with action Submit. This API expects a parameter array with at least the element form_type and also expects to find a handler class with the name of this form_type in the extension. So currenty it can deal with a form which has form_type CoachingIndividual and the extension has the handler class CRM_Wpcivi_CoachingIndividual. This class extends the abstract class CRM_Wpcivi_ApiHandler and has to implement the method processParams. In this method the actual form data is processed. In our example, a contact is created and an activity of a specific type (with custom data) is created. If you would like to use this approach as a basis for your own needs you could remove the CoachingIndividual handler and add your own handler(s).

The extension can be found on GitHub: https://github.com/CiviCooP/be.werkmetzin.wpcivi and will not be in the CiviCRM extension directory as it is not a generic extension. But feel free to use as a basis for your own stuff!

And if you want to know more you can always contact Jaap Jansma or me. (jaap dot jansma at civicoop dot org or erik dot hommel at civicoop dot org)

 

Comments

Is there a Github repo for the WordPress plugin? I have some technical suggestions I'd like to make, but can't find an appropriate place to do so.

Thanks!

I had some email conversation with Josh showing some misunderstanding to what this extension can do. So let me try to enhance the explanation with 2 examples....

Example 1
User story: as a logged in user I want to be able to enter my contact data like first name, last name, birth date, gender.
In this case I can use Contact Form 7 and the CiviCRM plugin that is mentioned in the blog post. For the CiviCRM part I need one API call (Contact Create). In the plugin part of the form I would add the API entity and action (and site key and pai key and url of CiviCRM) AND make sure that the field names on my Wordpress form have the same name as the  fields in the API (first_name, last_name, genter, birth_date). In that case I do not need the CiviCRM extension and what I just described is enough to communicate with CiviCRM. No action on the CiviCRM side needeed.

Example 2
User story: as an anonymous user I want to be able to set up a meeting with a consultant on the website.
In this user story I have no standard API call I can use. The issue is not so much the CiviCRM Wordpress plugin but that what I want to achieve is not handled by a core CiviCRM API. So I would add a form in Wordpress with all the data, and create a specific CiviCRM API to process the data in CiviCRM. That is where the CiviCRM extension comes in to play as it is a handy way to handle the CiviCRM processing linked to the Wordpress form.

So the 'magic' is in the Wordpress plugin, and it can be enhanced with a specific CiviCRM extension modelled on our example. I hope this enhances the understanding :-)