Skip to content

Commit

Permalink
gppa-split-new-lines-into-choices.php: Added new snippet.
Browse files Browse the repository at this point in the history
  • Loading branch information
spivurno authored Nov 21, 2023
1 parent f59084f commit 8a16dc8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gp-populate-anything/gppa-split-new-lines-into-choices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Gravity Perks // Populate Anything // Split New Lines into Chocies
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
*
* Instruction Video: Incoming...
*
* Split new lines into separate choices when populating from Paragraph fields (or any other value that may contain new lines).
*/
// Update "123" to your form ID and "4" to your field ID.
add_filter( 'gppa_input_choices_123_4', function ( $choices, $field, $objects ) {
$new_choices = array();
foreach ( $choices as $choice ) {
$values = array_map( 'trim', explode( "\n", $choice['value'] ) );
foreach ( $values as $value ) {
$new_choices[] = array(
'text' => $value,
'value' => $value,
'isSelected' => false,
);
}
}

return $new_choices;
}, 10, 3 );

0 comments on commit 8a16dc8

Please sign in to comment.