Skip to content

feat(integration): add Simple Basic Contact Form integration#820

Open
faisalahammad wants to merge 1 commit intoibericode:mainfrom
faisalahammad:feature/issue-753-simple-basic-contact-form-integration
Open

feat(integration): add Simple Basic Contact Form integration#820
faisalahammad wants to merge 1 commit intoibericode:mainfrom
faisalahammad:feature/issue-753-simple-basic-contact-form-integration

Conversation

@faisalahammad
Copy link
Contributor

@faisalahammad faisalahammad commented Feb 16, 2026

🎯 Summary

Adds a new integration with the Simple Basic Contact Form plugin, allowing users to subscribe to Mailchimp lists via an opt-in checkbox on SBCF contact forms.

📋 Issue Reference

Fixes #753

As requested on WordPress.org support.

🔍 Problem Description

Current Behavior

The Simple Basic Contact Form plugin has no Mailchimp integration. Users who rely on SBCF for their contact forms cannot offer Mailchimp newsletter subscriptions through those forms.

Expected Behavior

An opt-in checkbox should appear inside the Simple Basic Contact Form, and when checked, the form submitter's data should be sent to the selected Mailchimp list.

✨ Solution Overview

Approach Taken

Created a new MC4WP_Simple_Basic_Contact_Form_Integration class that follows the exact same pattern used by the existing CF7 and Comment Form integrations. The integration hooks into two SBCF extension points:

  1. scf_filter_contact_form (filter) — Injects the MC4WP checkbox HTML into the form before the </form> closing tag
  2. scf_send_email (action) — Processes the subscription after the contact form email is successfully sent

Why This Approach

  • Proven pattern: Mirrors the existing CF7 integration architecture, which handles the same use case (third-party form → checkbox → subscribe)
  • Stable hooks: Both scf_filter_contact_form and scf_send_email are well-established hooks in the SBCF plugin
  • Non-invasive: The form's original behavior is completely unaffected — the checkbox is only added visually and subscription only triggers when explicitly checked
  • Field guessing: Uses MC4WP_Field_Guesser on $_POST data (same as CF7) to automatically map form fields to Mailchimp merge fields

Alternatives Considered

  1. Using scf_custom_fields hook: Only suitable for adding extra form fields, not for injecting a checkbox with custom behavior. Would require more complex HTML manipulation.
  2. Output buffering approach: Fragile and could interfere with other plugins. The scf_filter_contact_form filter is the intended extension point for modifying form HTML.

🔧 Changes Made

Files Modified

File Change
integrations/simple-basic-contact-form/class-simple-basic-contact-form.php [NEW] Integration class
autoload.php Added classmap entry for new class
integrations/bootstrap.php Registered integration with mc4wp_register_integration()

Detailed Changes

1. Integration Class (New File)

class MC4WP_Simple_Basic_Contact_Form_Integration extends MC4WP_Integration

Key methods:

Method Purpose
add_hooks() Registers scf_filter_contact_form filter and scf_send_email action
add_checkbox($form_html) Injects checkbox HTML before </form> using str_ireplace()
process($recipient, $topic, $message, $headers, $email) Checks if checkbox was ticked, uses MC4WP_Field_Guesser to extract data, falls back to the $email action parameter if EMAIL not found via guesser
is_installed() Returns function_exists('simple_contact_form')
get_ui_elements() Removes 'implicit' — explicit checkbox only (same as CF7)

Why this works:

The scf_send_email action fires at line 674 of the SBCF plugin after successful form validation and email delivery. This ensures:

  • The subscription only happens when form submission succeeds
  • The sender's $email is available as a reliable fallback
  • All $_POST data is still accessible for field guessing

2. Autoload Registration

 'MC4WP_Registration_Form_Integration' => '/integrations/wp-registration-form/class-registration-form.php',
+'MC4WP_Simple_Basic_Contact_Form_Integration' => '/integrations/simple-basic-contact-form/class-simple-basic-contact-form.php',
 'MC4WP_Tools' => '/includes/class-tools.php',

3. Bootstrap Registration

 mc4wp_register_integration('give', 'MC4WP_Give_Integration');
+mc4wp_register_integration('simple-basic-contact-form', 'MC4WP_Simple_Basic_Contact_Form_Integration');
 mc4wp_register_integration('custom', 'MC4WP_Custom_Integration', true);

🧪 Testing Performed

Automated Testing

$ vendor/bin/phpunit
PHPUnit 9.6.34 by Sebastian Bergmann and contributors.

......................................................            54 / 54 (100%)

Time: 00:00.021, Memory: 6.00 MB

OK (54 tests, 175 assertions)

✅ All 54 existing tests pass with 175 assertions — no regressions.

Manual Testing

Test Case 1: Integration Visibility

Steps:

  1. Activate both MC4WP and Simple Basic Contact Form plugins
  2. Navigate to Mailchimp for WP → Integrations

Expected: "Simple Basic Contact Form" appears in the integrations list
Actual: ✅ Integration visible with correct name and description

Test Case 2: Checkbox Rendering

Steps:

  1. Configure the SBCF integration (select list, set label)
  2. Visit a page with the [simple_contact_form] shortcode

Expected: MC4WP checkbox appears inside the form, before submit
Actual: ✅ Checkbox renders correctly within the form

Test Case 3: Subscription Flow

Steps:

  1. Fill out the contact form with valid data
  2. Check the MC4WP checkbox
  3. Submit the form

Expected: Email is added to the selected Mailchimp list
Actual: ✅ Subscription processed successfully

Test Case 4: Opt-out Respected

Steps:

  1. Fill out the contact form
  2. Leave the MC4WP checkbox unchecked
  3. Submit the form

Expected: No Mailchimp subscription happens
Actual: ✅ No subscription — form email sent normally

📊 Performance Impact

Analysis: ✅ Negligible impact

  • No additional database queries — Integration uses the same options loading mechanism as all existing integrations
  • No external API calls unless checkbox is checked — The Mailchimp API is only contacted when the user explicitly opts in
  • Filter/action hooks are lightweightstr_ireplace() for checkbox injection and $_POST reading for field guessing are trivial operations

🔒 Security Considerations

  • Input sanitization: All user data is processed through MC4WP_Field_Guesser, which handles sanitization
  • Checkbox verification: Uses $this->triggered() from the base class, which properly checks for the checkbox value
  • No direct database access: All data flows through the existing MC4WP subscription pipeline
  • Email validation: Handled by the base MC4WP_Integration::subscribe() method

♿ Accessibility

  • ✅ Checkbox HTML is generated by $this->get_checkbox_html() from the base class, which follows the same accessible markup pattern used across all other integrations

🌍 Internationalization

  • $name and $description follow the same pattern as existing integrations (English strings, consistent with codebase convention)
  • ✅ Checkbox label is user-configurable through the admin UI

⚠️ Breaking Changes

No breaking changes — This is a purely additive feature. Existing integrations and functionality are completely unaffected.

Screenshots

CleanShot 2026-02-16 at 22 52 28@2x CleanShot 2026-02-16 at 22 52 17@2x

Plugin build/zip

mailchimp-for-wp-fix-issue-753.zip

✅ PR Checklist

  • Code follows WordPress Coding Standards
  • All functions have proper PHPDoc blocks
  • Follows existing integration patterns (CF7, Comment Form)
  • No PHP warnings/errors
  • Backward compatible — purely additive
  • Tests pass successfully (54 tests, 175 assertions)
  • Self-reviewed for quality

Ready for Review

- Add MC4WP_Simple_Basic_Contact_Form_Integration class
- Hook into scf_filter_contact_form to inject checkbox
- Hook into scf_send_email to process subscription
- Register class in autoload classmap
- Register integration in bootstrap

Fixes ibericode#753
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add integration with Simple Basic Contact Form plugin

1 participant