Skip to content

Commit

Permalink
Update value override handling for pre populating
Browse files Browse the repository at this point in the history
  • Loading branch information
sclark3-godaddy committed Mar 2, 2024
1 parent dcce8d6 commit 2bf9ccd
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions includes/Pods_GF.php
Original file line number Diff line number Diff line change
Expand Up @@ -2250,6 +2250,8 @@ public static function gf_prepopulate( $form, $ajax = false, $prepopulate = null
// Allow for value to be overridden by existing prepopulation or callback
$value_override = $field_options['value'];

// @todo Fix prepopulating for field types: name and address (mapped to indiv inputs), file, consent, post_tag (multiple, comma separated), post_image.

if ( null === $value_override && isset( $gf_field->allowsPrepopulate ) && $gf_field->allowsPrepopulate ) {
// @todo handling for field types that have different $_POST input names

Expand Down Expand Up @@ -2462,13 +2464,40 @@ public static function gf_prepopulate( $form, $ajax = false, $prepopulate = null
if ( is_array( $value_override ) && 'list' === $gf_field->type ) {
$choices = $gf_field->choices;

$value_override_chunked = array_chunk( $value_override, count( $choices ) );
$total_choices = count( $choices );

// Check if the values are chunked already.
if ( isset( $value_override[0] ) && is_array( $value_override[0] ) && $total_choices === count( $value_override[0] ) ) {
foreach ( $value_override as $vo_key => $value_override_row ) {
$value_override[ $vo_key ] = implode( '|', $value_override_row );
}

$value_override = implode( ',', $value_override );
} else {
$value_override_chunked = array_chunk( $value_override, $total_choices );

foreach ( $value_override_chunked as $k => $v ) {
$value_override_chunked[ $k ] = implode( '|', $v );
}

foreach ( $value_override_chunked as $k => $v ) {
$value_override_chunked[ $k ] = implode( '|', $v );
$value_override = implode( ',', $value_override_chunked );
}

$value_override = implode( ',', $value_override_chunked );
// @todo Figure this out, the 2.0 code had a count === 1 check that doesn't seem to make sense anymore.

/*if ( is_array( $gf_field->choices ) && 1 === count( $gf_field->choices ) ) {
$choices = $gf_field->choices;
$value_override_chunked = array_chunk( $value_override, count( $choices ) );
foreach ( $value_override_chunked as $k => $v ) {
$value_override_chunked[ $k ] = implode( '|', $v );
}
} else {
$value_override_chunked = $value_override;
}
$value_override = implode( ',', $value_override_chunked );*/
}

$_GET[ 'pods_gf_field_' . $field ] = pods_slash( $value_override );
Expand All @@ -2488,6 +2517,8 @@ public static function gf_prepopulate( $form, $ajax = false, $prepopulate = null
}
}

pods_debug( $_GET );

return $form;

}
Expand Down

0 comments on commit 2bf9ccd

Please sign in to comment.