diff --git a/includes/formscrm-library/class-contactform7.php b/includes/formscrm-library/class-contactform7.php index eb22bfe..52eb83c 100644 --- a/includes/formscrm-library/class-contactform7.php +++ b/includes/formscrm-library/class-contactform7.php @@ -322,7 +322,7 @@ public function get_merge_vars( $cf7_crm, $submitted_data ) { } $crm_key = str_replace( 'fc_crm_field-', '', $key ); - if ( ! empty( $submitted_data[ $value ] ) ) { + if ( isset( $submitted_data[ $value ] ) ) { $value = $submitted_data[ $value ]; } diff --git a/tests/Forms/test-contactform.php b/tests/Forms/test-contactform.php index 4b4418d..d6c808c 100644 --- a/tests/Forms/test-contactform.php +++ b/tests/Forms/test-contactform.php @@ -46,4 +46,48 @@ public function test_get_merge_vars() { array( 'name' => 'custom_fields|info_chat', 'value' => 'Autónomo' ), ) ); } + + /** + * GDPR checkbox unchecked: CF7 submits empty array, value must be '' not the field name. + */ + public function test_get_merge_vars_gdpr_unchecked() { + $cf7_crm = array( + 'fc_crm_type' => 'clientify', + 'fc_crm_apipassword' => 'api-password', + 'fc_crm_module' => 'Contacts', + 'fc_crm_field-gdpr_accept' => 'extra-info', + ); + + $submitted_data = array( + 'extra-info' => array(), // Unchecked checkbox returns empty array in CF7. + ); + + $merge_vars = $this->contact_form->get_merge_vars( $cf7_crm, $submitted_data ); + $this->assertEquals( + array( array( 'name' => 'gdpr_accept', 'value' => '' ) ), + $merge_vars + ); + } + + /** + * GDPR checkbox checked: CF7 submits the label string, value must be non-empty. + */ + public function test_get_merge_vars_gdpr_checked() { + $cf7_crm = array( + 'fc_crm_type' => 'clientify', + 'fc_crm_apipassword' => 'api-password', + 'fc_crm_module' => 'Contacts', + 'fc_crm_field-gdpr_accept' => 'extra-info', + ); + + $submitted_data = array( + 'extra-info' => array( 'Me gustaría estar al tanto de las novedades de Ipace' ), + ); + + $merge_vars = $this->contact_form->get_merge_vars( $cf7_crm, $submitted_data ); + $this->assertEquals( + array( array( 'name' => 'gdpr_accept', 'value' => 'Me gustaría estar al tanto de las novedades de Ipace' ) ), + $merge_vars + ); + } }