From 3b64bd47a1f88d5a89a1a5cb2046a397390f8c6e Mon Sep 17 00:00:00 2001 From: Malay Ladu Date: Fri, 28 Mar 2025 23:24:36 +0530 Subject: [PATCH] `gw-list-field-as-choices.php`: Added snippet usage examples from `gw-list-field-as-choices-usage.php`. --- .../gw-list-field-as-choices-usage.php | 60 ------------------- gravity-forms/gw-list-field-as-choices.php | 59 ++++++++++++++++-- 2 files changed, 54 insertions(+), 65 deletions(-) delete mode 100644 gravity-forms/gw-list-field-as-choices-usage.php diff --git a/gravity-forms/gw-list-field-as-choices-usage.php b/gravity-forms/gw-list-field-as-choices-usage.php deleted file mode 100644 index c68f0d65e..000000000 --- a/gravity-forms/gw-list-field-as-choices-usage.php +++ /dev/null @@ -1,60 +0,0 @@ - 1, - 'list_field_id' => 2, - 'choice_field_ids' => 3, -) ); - -# Enable Sorting of Choices Alphanumerically -new GW_List_Field_As_Choices( array( - 'form_id' => 1, - 'list_field_id' => 2, - 'choice_field_ids' => 3, - 'sort' => true, -) ); - -# Populating Multiple Choice Fields -new GW_List_Field_As_Choices( array( - 'form_id' => 384, - 'list_field_id' => 3, - 'choice_field_ids' => array( 6, 7 ), -) ); - -# Customizing the Choice Label and Value -new GW_List_Field_As_Choices( array( - 'form_id' => 384, - 'list_field_id' => 2, - 'choice_field_ids' => array( 4, 5 ), - 'label_template' => '{Name} ({Age})', - 'value_template' => '{Name}', -) ); - -# Filter Usage - -## Customize List field values to be populated as choices based on Gravity Flow User Input step. -add_filter( 'gwlfac_list_field_values', function( $values, $form, $args ) { - if ( is_array( $values ) ) { - return $values; - } - - // Confirm we are within a Gravity Flow Inbox. - if ( rgget( 'lid' ) && rgget( 'page' ) == 'gravityflow-inbox' ) { - $entry = GFAPI::get_entry( (int) rgget( 'lid' ) ); - // Verify the entry list field has previously stored values to use. - if ( $entry ) { - $values = unserialize( $entry[ $args['list_field_id'] ] ); - if ( ! is_array( $values ) ) { - return false; - } else { - return $values; - } - } - } - return false; -}, 10, 3 ); diff --git a/gravity-forms/gw-list-field-as-choices.php b/gravity-forms/gw-list-field-as-choices.php index 1b6cb5111..076c4a641 100644 --- a/gravity-forms/gw-list-field-as-choices.php +++ b/gravity-forms/gw-list-field-as-choices.php @@ -154,8 +154,57 @@ function is_applicable_field( $field ) { */ # Basic Usage -# new GW_List_Field_As_Choices( array( -# 'form_id' => 1, -# 'list_field_id' => 2, -# 'choice_field_ids' => 3 -# ) ); +//new GW_List_Field_As_Choices( array( +// 'form_id' => 1, +// 'list_field_id' => 2, +// 'choice_field_ids' => 3, +//) ); + + +# Enable Sorting of Choices Alphanumerically +//new GW_List_Field_As_Choices( array( +// 'form_id' => 1, +// 'list_field_id' => 2, +// 'choice_field_ids' => 3, +// 'sort' => true, +//) ); + +# Populating Multiple Choice Fields +//new GW_List_Field_As_Choices( array( +// 'form_id' => 384, +// 'list_field_id' => 3, +// 'choice_field_ids' => array( 6, 7 ), +//) ); + + +# Customizing the Choice Label and Value +//new GW_List_Field_As_Choices( array( +// 'form_id' => 384, +// 'list_field_id' => 2, +// 'choice_field_ids' => array( 4, 5 ), +// 'label_template' => '{Name} ({Age})', +// 'value_template' => '{Name}', +//) ); + +# Filter Usage +## Customize List field values to be populated as choices based on Gravity Flow User Input step. +//add_filter( 'gwlfac_list_field_values', function( $values, $form, $args ) { +// if ( is_array( $values ) ) { +// return $values; +// } + +# Confirm we are within a Gravity Flow Inbox. +// if ( rgget( 'lid' ) && rgget( 'page' ) == 'gravityflow-inbox' ) { +// $entry = GFAPI::get_entry( (int) rgget( 'lid' ) ); +// // Verify the entry list field has previously stored values to use. +// if ( $entry ) { +// $values = unserialize( $entry[ $args['list_field_id'] ] ); +// if ( ! is_array( $values ) ) { +// return false; +// } else { +// return $values; +// } +// } +// } +// return false; +//}, 10, 3 );