Skip to content

Fix GDPR checkbox handling for unchecked state in CF7 forms#178

Merged
davidperezgar merged 1 commit intotrunkfrom
claude/revert-clientify-v2-ubJP9
Mar 30, 2026
Merged

Fix GDPR checkbox handling for unchecked state in CF7 forms#178
davidperezgar merged 1 commit intotrunkfrom
claude/revert-clientify-v2-ubJP9

Conversation

@davidperezgar
Copy link
Copy Markdown
Contributor

Summary

Fixed a bug in the Contact Form 7 integration where unchecked GDPR checkboxes were not being properly handled when submitting data to the CRM. The issue was that empty arrays (submitted by CF7 for unchecked checkboxes) were being treated as falsy values, preventing the field from being included in the merge variables.

Key Changes

  • Changed the condition in get_merge_vars() from ! empty() to isset() to properly handle empty arrays submitted by CF7 for unchecked checkboxes
  • Added test case test_get_merge_vars_gdpr_unchecked() to verify that unchecked GDPR checkboxes result in an empty string value
  • Added test case test_get_merge_vars_gdpr_checked() to verify that checked GDPR checkboxes properly pass through the label text

Implementation Details

The fix distinguishes between:

  • Unchecked checkbox: CF7 submits an empty array [], which should map to an empty string '' in the CRM field
  • Checked checkbox: CF7 submits an array with the label string, which should be passed through as-is

By using isset() instead of ! empty(), the code now correctly processes both states, ensuring GDPR consent fields are always included in the CRM submission with the appropriate value.

https://claude.ai/code/session_01L5SX14n8w68mnppe99jPDg

…unchecked

When a CF7 checkbox was unchecked, CF7 submitted an empty array for the field.
The !empty() guard in get_merge_vars() treated that as "no value", leaving $value
as the CF7 field name string (e.g. "extra-info"). That non-empty string then caused
gdpr_accept to be evaluated as true in Clientify's create_entry(), meaning every
contact was marked as having accepted GDPR even when they had not.

Switching to isset() ensures the actual submitted value (empty array → empty string
after implode) is used, so gdpr_accept correctly resolves to false for unchecked
and true for checked checkboxes.

Adds two regression tests covering both states.

Fixes #176

https://claude.ai/code/session_01L5SX14n8w68mnppe99jPDg
@davidperezgar davidperezgar merged commit a6a1465 into trunk Mar 30, 2026
6 checks passed
@davidperezgar davidperezgar deleted the claude/revert-clientify-v2-ubJP9 branch March 30, 2026 11:32
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.

2 participants