Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/formscrm-library/class-contactform7.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}

Expand Down
44 changes: 44 additions & 0 deletions tests/Forms/test-contactform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Loading