From e89d0ba724567d920a53f2b0b00e4d309cc997a0 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Sat, 5 Apr 2025 06:42:01 +0530 Subject: [PATCH] `gpcc-copy-to-conditionally-hidden-fields.php`: Fixed an issue with copying value with multi input field triggers. --- ...cc-copy-to-conditionally-hidden-fields.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gp-copy-cat/gpcc-copy-to-conditionally-hidden-fields.php b/gp-copy-cat/gpcc-copy-to-conditionally-hidden-fields.php index 1ff423556..44024c133 100644 --- a/gp-copy-cat/gpcc-copy-to-conditionally-hidden-fields.php +++ b/gp-copy-cat/gpcc-copy-to-conditionally-hidden-fields.php @@ -29,8 +29,23 @@ continue; } - $source_field = GFAPI::get_field( $form, $target['source'] ); - $source_values = $source_field->get_value_submission( array() ); + $source_field = GFAPI::get_field( $form, $target['source'] ); + $source_values = $source_field->get_value_submission( array() ); + $condition_field = GFAPI::get_field( $form, $target['condition'] ); + $condition_value = $condition_field->get_value_submission( $entry ); + + // for multi-input fields, we need to check the index + // to see if the condition is met. + if ( strpos( $target['condition'], '.' ) !== false ) { + list( $base, $index ) = explode( '.', $target['condition'] ); + if ( isset( $condition_field['choices'][ (int) $index ] ) ) { + if ( $condition_field['choices'][ (int) $index ]['value'] !== $condition_value ) { + continue; + } + } else { + continue; + } + } if ( is_array( $source_values ) ) { foreach ( $source_values as $input_id => $source_value ) {