Description
When the same form field is mapped to multiple CRM fields in an Elementor form (e.g., sending the same value to different modules simultaneously), only the first CRM field mapping is processed. All subsequent mappings of that form field are silently ignored.
Root Cause
In includes/formscrm-library/class-elementor.php, the run() method normalizes form data into $merge_vars using array_search():
// lines 267–278
$merge_vars = array();
foreach ( $raw_fields as $id => $field ) {
$key = array_search( $id, $hidden_settings, true ); // only finds FIRST match
if ( false === $key ) {
continue;
}
$field_id = str_replace( 'fc_crm_field-', '', $key );
$merge_vars[] = array(
'name' => $field_id,
'value' => $field['value'] ?? '',
);
}
array_search() returns only the first key where the form field ID appears as a value in $hidden_settings. When the same form field (e.g., email) is mapped to multiple CRM fields (e.g., fc_crm_field-contact_email and fc_crm_field-lead_email), the $hidden_settings contains:
{
"fc_crm_field-contact_email": "email",
"fc_crm_field-lead_email": "email"
}
array_search("email", $hidden_settings, true) returns only fc_crm_field-contact_email. The fc_crm_field-lead_email mapping is never added to $merge_vars.
Steps to Reproduce
- Set up an Elementor Pro form with FormsCRM action.
- Connect to a CRM that has multiple modules (e.g., Contacts and Leads).
- Map the same form field (e.g., the "Name" field) to a CRM field in each module.
- Submit the form.
- Observe that only the first module receives the value; the second module's field is empty.
Expected Behavior
All CRM field mappings that reference the same form field should receive the form field's value. $merge_vars should contain one entry per CRM field mapping, even when multiple CRM fields point to the same source form field.
Fix
Replace array_search() with array_keys() to retrieve all matching keys, then iterate over them:
$merge_vars = array();
foreach ( $raw_fields as $id => $field ) {
$keys = array_keys( $hidden_settings, $id, true ); // returns ALL matches
foreach ( $keys as $key ) {
$field_id = str_replace( 'fc_crm_field-', '', $key );
$merge_vars[] = array(
'name' => $field_id,
'value' => $field['value'] ?? '',
);
}
}
Affected File
includes/formscrm-library/class-elementor.php, lines 267–278
Description
When the same form field is mapped to multiple CRM fields in an Elementor form (e.g., sending the same value to different modules simultaneously), only the first CRM field mapping is processed. All subsequent mappings of that form field are silently ignored.
Root Cause
In
includes/formscrm-library/class-elementor.php, therun()method normalizes form data into$merge_varsusingarray_search():array_search()returns only the first key where the form field ID appears as a value in$hidden_settings. When the same form field (e.g.,email) is mapped to multiple CRM fields (e.g.,fc_crm_field-contact_emailandfc_crm_field-lead_email), the$hidden_settingscontains:{ "fc_crm_field-contact_email": "email", "fc_crm_field-lead_email": "email" }array_search("email", $hidden_settings, true)returns onlyfc_crm_field-contact_email. Thefc_crm_field-lead_emailmapping is never added to$merge_vars.Steps to Reproduce
Expected Behavior
All CRM field mappings that reference the same form field should receive the form field's value.
$merge_varsshould contain one entry per CRM field mapping, even when multiple CRM fields point to the same source form field.Fix
Replace
array_search()witharray_keys()to retrieve all matching keys, then iterate over them:Affected File
includes/formscrm-library/class-elementor.php, lines 267–278