Skip to content

Bug: Elementor merge fields only maps first occurrence, ignores duplicate form field mappings #179

@davidperezgar

Description

@davidperezgar

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

  1. Set up an Elementor Pro form with FormsCRM action.
  2. Connect to a CRM that has multiple modules (e.g., Contacts and Leads).
  3. Map the same form field (e.g., the "Name" field) to a CRM field in each module.
  4. Submit the form.
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions