5

I have a complicated Google Form I've already written. While it could be reimplemented in Caldera Forms, this would be time-consuming, and Caldera Forms is no longer being developed. Is there a way to integrate Google Forms with CiviCRM?

6

You can do this by adding a Google Script and trigger to your Google Form, and installing Form Processor on the CiviCRM side.

Configuring Form Processor is out of scope of this question - there are documentation and blog posts available to explain that. However, no documentation exists for the Google side.

Instructions

  • From the Google Forms editing screen, click the More menu (three vertical dots) and select Script Editor.
    • This won't appear if you're too zoomed in.
  • Paste the following code into the editor and press Save (latest version on Github):
/**
 * @OnlyCurrentDoc
 */

function onFormSubmit(event) {

  // Set the values on these four lines for your Form Processor and site.
  var url = '<API3 REST Endpoint here>';
  var api_key = '<api key here>';
  var site_key = '<site key here>';
  var form_processor_machine_name = '<machine name of Form Processor here>';

  // Don't modify anything below this line.
  var submission = {};
  var responses = event.response.getItemResponses();
  for (var i = 0; i < responses.length; i++) {
    // Convert all non-alphanumeric values in the title to underscores, lowercase as well.
    title = responses[i].getItem().getTitle().replace(/[\W]+/g,"_").toLowerCase();
    submission[title] = responses[i].getResponse();
  }
  

  var payload = { 
    "entity": "FormProcessor",
    "action": form_processor_machine_name,
    "json": JSON.stringify(submission),
    "api_key" : api_key,
    "key": site_key,
  }
  var options = {
    "method" : "post",
    "payload" : payload,
    "muteHttpExceptions" : true,
  };

  Logger.log(JSON.stringify(submission));
  // Fire the webhook.
  var response = UrlFetchApp.fetch(url,options);
}
  • Modify the indicated lines at the top of the script to add these values:

    • The URL of your REST endpoint (varies by CMS and by CiviCRM version; check the REST Endpoint documentation);
    • The API key of a user with the necessary permission specified by your Form Processor configuration;
    • The site key (can be found in civicrm.settings.php);
    • The machine name of your Form Processor instance (can be found in the configuration).
  • In the Google Script editor left navigation, click the Triggers tab, click Add a Trigger and configure it as follows:

    • Choose which function to run: onFormSubmit
    • Which runs at deployment: Head
    • Select event source: From form
    • Select event type: On form submit.
    • NOTE: If you create the trigger before adding the code, Google won't ask you to authorize the necessary scopes. Create the trigger last.

Now your forms will send the data to CiviCRM when they're submitted! To find the names of the inputs to configure Form Processor, do a test form submission, then in Google Script editor, click the Executions tab. The script will log the payload to Form Processor, and you can easily see the names of the fields as CiviCRM will see them.

1
  • Very nice, @Jon. Thanks for sharing this useful documentation.
    – Joe Murray
    May 4 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.