Drupal Integration Guide

Complete guide to integrate MyFormCapture with Drupal

Setup time: 10-15 minutes
Difficulty: Intermediate
Compatible versions: Drupal 8.x, 9.x, 10.x

Integrate MyFormCapture with your Drupal website to capture leads from contact forms, webforms, and custom forms. Drupal powers over 1 million websites worldwide and offers powerful content management capabilities.

Prerequisites

  • A MyFormCapture account - Sign up here
  • Your MyFormCapture integration code from your dashboard
  • Drupal admin access (Administrator role)
  • Drupal 8.x, 9.x, or 10.x installation
  • Basic understanding of Drupal modules (for custom module method)

Integration Methods

Custom Module

15 minutes Intermediate

Create a custom Drupal module for MyFormCapture integration. This is the most maintainable and Drupal-friendly approach.

1

Create Module Directory

Set up the basic module structure in your Drupal installation.
  1. Navigate to /modules/custom in your Drupal root directory
  2. Create a new directory called myformcapture_integration
  3. Create the module info file myformcapture_integration.info.yml
name: 'MyFormCapture Integration'
type: module
description: 'Integrates MyFormCapture lead capture widget with Drupal'
package: Custom
core_version_requirement: ^8 || ^9 || ^10
version: '1.0.0'
dependencies:
  - drupal:system
Important Note
The info.yml file defines your module and its dependencies. Make sure indentation is correct as YAML is sensitive to spacing.
2

Create Module Files

Add the main module files to handle MyFormCapture integration.
  1. Create myformcapture_integration.module file
  2. Create myformcapture_integration.libraries.yml file
  3. Create js/myformcapture.js file in your module directory
<?php

/**
 * @file
 * MyFormCapture Integration module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function myformcapture_integration_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.myformcapture_integration':
      return '<p>' . t('MyFormCapture integration for capturing leads.') . '</p>';
  }
}

/**
 * Implements hook_page_attachments().
 */
function myformcapture_integration_page_attachments(array &$attachments) {
  $attachments['#attached']['library'][] = 'myformcapture_integration/myformcapture';
}
Important Note
The hook_page_attachments() function ensures the MyFormCapture script loads on every page.
3

Create Library Definition

Define the JavaScript library that will load MyFormCapture on your site.
myformcapture:
  js:
    js/myformcapture.js: {}
  dependencies:
    - core/drupal
    - core/jquery
Important Note
Libraries in Drupal handle JavaScript and CSS loading efficiently. This ensures proper loading order and caching.
4

Add JavaScript File

Create the JavaScript file that initializes MyFormCapture.
(function ($, Drupal, drupalSettings) {
  'use strict';

  Drupal.behaviors.myformcaptureIntegration = {
    attach: function (context, settings) {
      // Use once() to ensure the script only runs once per element
      $(context).find('body').once('myformcapture').each(function() {
        // Load MyFormCapture script dynamically
        var script = document.createElement('script');
        script.src = 'https://widget.callmebackbutton.com/widget.js';
        script.setAttribute('data-account', 'YOUR_ACCOUNT_ID');
        script.setAttribute('data-drupal', 'true');
        document.head.appendChild(script);
      });
    }
  };

})(jQuery, Drupal, drupalSettings);
Important Note
Replace 'YOUR_ACCOUNT_ID' with your actual MyFormCapture account ID. The data-drupal attribute helps optimize for Drupal-specific features.
5

Enable and Test Module

Activate the module and verify the integration works.
  1. Go to Extend in your Drupal admin
  2. Find 'MyFormCapture Integration' and check the checkbox
  3. Click Install
  4. Clear cache via Configuration → Performance → Clear all caches
  5. Visit your site to verify the widget appears
Important Note
Always clear cache after enabling new modules. Check browser console for any JavaScript errors.

Next Steps

Configure MyFormCapture

  • Set up your business hours and timezone
  • Configure callback phone numbers
  • Set up email notifications
  • Add team members to your account

Advanced Features

  • Set up custom form templates
  • Configure lead scoring rules
  • Integrate with your CRM
  • Set up automated workflows

Need Help?

Our support team is here to help you with your integration.

Contact Support