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
58 changes: 30 additions & 28 deletions classes/helpers/FrmEntriesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public static function set_other_repeating_vals( $field, &$value, &$args ) {
* @return void
*/
public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
// Checkboxes and multi-select dropdowns.
// Checkboxes.
if ( is_array( $value ) && $field->type === 'checkbox' ) {
// Combine "Other" values with checked values. "Other" values will override checked box values.
foreach ( $other_vals as $k => $v ) {
Expand All @@ -568,36 +568,38 @@ public static function set_other_validation_val( &$value, $other_vals, $field, &
if ( is_array( $value ) && $value ) {
$value = array_merge( $value, $other_vals );
}
} else {
// Radio and dropdowns.
$other_key = array_filter( array_keys( $field->options ), 'is_string' );
$other_key = reset( $other_key );

// Multi-select dropdown.
if ( is_array( $value ) ) {
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
$o_key = array_search( $field->options[ $other_key ], $value );

if ( $o_key !== false ) {
// Modify the original value so other key will be preserved.
$value[ $other_key ] = $value[ $o_key ];

// By default, the array keys will be numeric for multi-select dropdowns.
// If going backwards and forwards between pages, the array key will match the other key.
if ( $o_key !== $other_key ) {
unset( $value[ $o_key ] );
}

$args['temp_value'] = $value;
$value[ $other_key ] = reset( $other_vals );
return;
}

// Radio and dropdowns.
$other_key = array_filter( array_keys( $field->options ), 'is_string' );
$other_key = reset( $other_key );

if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
unset( $value[ $other_key ] );
}
// Multi-select dropdown.
if ( is_array( $value ) ) {
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
$o_key = array_search( $field->options[ $other_key ], $value );

if ( $o_key !== false ) {
// Modify the original value so other key will be preserved.
$value[ $other_key ] = $value[ $o_key ];

// By default, the array keys will be numeric for multi-select dropdowns.
// If going backwards and forwards between pages, the array key will match the other key.
if ( $o_key !== $other_key ) {
unset( $value[ $o_key ] );
}

$args['temp_value'] = $value;
$value[ $other_key ] = reset( $other_vals );

if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
unset( $value[ $other_key ] );
}
} elseif ( $field->options[ $other_key ] == $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
$value = $other_vals;
}//end if
}
} elseif ( $field->options[ $other_key ] == $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
$value = $other_vals;
}//end if
}

Expand Down
Loading