This is a WordPress plugin that integrates the Gravity Forms plugin with CiviCRM using the Form Processor extension.
Develop forms that integrate with CiviCRM to add common features to your website like:
- Newsletter subscription form
- Donation form
- Contact details update form
- Credit card update details form
- Recurring donation update form
- Update Activity Details form
- CiviCRM must be installed locally on the same WordPress site as this plugin. Remote CiviCRM is not supported at this time, see issue #1
- Integration with the CiviCRM Form Processor uses Web Hooks, which requires the Gravity Forms Webhooks Add-on. This add-on is currently bundled with the Gravity Forms Elite License
Use the following steps to set up a Newsletter Subscription form using the example configuration provided.
- In WordPress, install and enable this plugin.
- On the CiviCRM Extensions page, install the following Extensions:
- In CiviCRM, locate the CiviCRM "System User" Contact. This is the user account used to execute CiviCRM cron and scheduled jobs. If you do not have such a user, then best to create one is now as this will be used by default for processing the form submissions; this user must have a corresponding WordPress user account.
- Open this CiviCRM Contact and click on the API Key tab.
- Generate a User API Key and copy the Site API Key.
- In WordPress, open Gravity Forms and import the example Gravity Form, gravityforms-newsletter_subscribe.json
- Open the imported Gravity Form, the following form should be displayed.
- Click on Webhooks
- Add a new Webhook
- Configure the Webhook
- Configure the Webhook as shown below.
- In the Request URL parameters for the Webhook, replace the following values:
{rest_api_url}
- This Gravity Forms, Webhook, Merge Tag will return the WordPress REST endpoint, for example: https://bananas.org.au/wp-json/key
, enter the CiviCRM Site API Keyapi_key
, enter the CiviCRM API Key- Example URL:
{rest_api_url}civicrm/v3/rest?entity=FormProcessor&action=newsletter_subscribe&key=SITEKEY&api_key=APIKEY&json=1
- Save the Webhook
- In CiviCRM, go to the Administer > Automation > Form Processors page,
/wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fadmin%2Fautomation%2Fformprocessor%2F#/formprocessors
- Import example Form Processor, civicrm-form-processor-newsletter_subscribe.json
- Edit the imported Form Processor. Verify that it has the required fields:
- first_name
- last_name
- In the Form Processor, edit the Add to group action and select the CiviCRM Group that the Contact should be subscribed to for the Contact: Add to group. This option must be set for the Add to group action to succeed.
- Note that the Form Processor has the name, newsletter_subscribe which used in the Webhook, Request URL. This is how the Webhook is connected to this Form Processor.
- Save the Form Processor.
- In WordPress, embed the Gravity Form in a new page.
- Open a new Web Browser window, not logged into the website. Go to the new page and submit the Gravity Form.
- In CiviCRM, confirm that the Contact was created and that the Contact was subscribed to the Group in CiviCRM.
When setting up your field in Gravity Forms, you can use a Merge Tag of the form {civicrm_fp.$processor.$field}
in the Default Value section of your Field's Advanced settings.
In the Newsletter Subscription above for example, you could fill in the Email field with the current user's email address recorded in CiviCRM, you would use {civicrm_fp.newsletter_subscribe.email}
, and set up the Retrieval of Defaults accordingly for the newsletter_subscribe Form Processor in CiviCRM.
The "Retrieval criteria for default data" specified in the form processor will be mapped to URL parameters when your Gravity Form is displayed to your users, such that if you create a criterion named cid
to retrieve contact details by ID, you'd be able to specify contact ID 1234 with a request like:
https://bananas.org.au/newsletter_subscribe?cid=1234
For Gravity Forms fields that support setting choices (e.g. Drop Down, Checkboxes, Radio Buttons), you may use predefined option lists set in CiviCRM. These either can use Option Groups defined in CiviCRM directly or may be defined by your Form Processor (recommended):
- Edit your Form Processor and add an input of one of the supported types:
- Yes/No as Option List
- Option Group
- Custom Options
- Mailing Group
- Tags
- Save your Form Processor
- Edit your Gravity form and add one of these types of field:
- Checkboxes or Multi Select (under Advanced Fields) for multiple option selection
- Radio Buttons or Drop Down to allow selection of a single option
- Under the General settings for your field, open the CiviCRM Source selection.
- Locate your Form Processor in the option list headings, and under it, select the field you defined in step 1.
- Press the "Edit Choices" button, and select "show values" - this will allow the CiviCRM options to be mapped directly. Note that the Choices will not appear filled from CiviCRM until you save the form and reload - also, if you change any options here your changes will be replaced with options filled from CiviCRM, so if you need to make any changes to the available options, including order, it is important to make them in the Form Processor configuration
- Save the Form and either Preview or embed it to see the changes
If you set defaults for the Form Processor input used as a "CiviCRM Source", these will be applied when the form is loaded, including any Retrieval criteria specified in the URL parameters.
Any Form Processor that should record actions as a specific Contact must implement checksum validation as part of the processor
- Include fields in the Form Processor that are used for the checksum validation
cid
for the Contact IDcs
for the Checksum
- These fields should also be included in Gravity Forms, using Merge Tags from the form processor as defaults
- Inside the Form processor "Retrieval of defaults" settings, use the "Contact: get contact ID of the currently logged in user" and "Contact: generate checksum" actions to provide default values to these fields
- You can also use the "Retrieval criteria for default data" to add
cid
andcs
criteria supporting checksum links generated from CiviCRM schedule reminders.- Works with any link that includes
?{contact.checksum}&cid={contact.id}
on the page with the Gravity Form. - Use the "Contact: validate checksum" action in Retrieval of Details to authenticate the link.
- Works with any link that includes
- As part of the Form Processor actions, you must use the "Contact: validate checksum" to authenticate the Contact ID and checksum used to submit the form.
- For Form Processors that must be processed on behalf of an existing contact, also use the "Contact: Validate checksum" action as part of the Form Processor Validation actions
An example of this setup is available,
- Import Gravity form: gravityforms-update_card.json
- Import Form Processor: civicrm-form-processor-update_card.json
This method is deprecated, instead provide a CiviCRM API Key for a CiviCRM Contact with sufficient permissions to execute the Form Processor or use the method described in the above section, Processing form submissions as a specific Contact.
The {civicrm_api_key}
Merge Tag will return the CiviCRM API Key for the user that submitted the form.
To troubleshoot this integration, enable the Gravity Forms Logging on the page /wp-admin/admin.php?page=gf_settings&subview=settings
and then check the Web Hooks logs when the Gravity Form is submitted. Logs are available on this page, /wp-admin/admin.php?page=gf_settings&subview=gravityformslogging
This should help you identify the cause of most issues integrating the Gravity Form and CiviCRM.
CiviCRM expects permalink settings to be set to "Post name" by default in order to address the wp-json
directory. Enable this setting on the page /wp-admin/options-permalink.php
if it is not set already.
If you are a Web Developer and know how to set up and use PHP Xdebug, it is useful to debug the Form Processor called by the Web Hook by appending &XDEBUG_SESSION=1 to the Web Hook URL in the Gravity Forms, Webhooks Feeds. This will trigger the Xdebug session to start.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see https://www.gnu.org/licenses/.
This WordPress plugin was developed by the team at Agileware.
Agileware provide a range of WordPress and CiviCRM development services including:
- CiviCRM migration
- CiviCRM integration
- CiviCRM extension development
- CiviCRM support
- CiviCRM hosting
- CiviCRM remote training services
Support your Australian CiviCRM developers, contact Agileware today!