Skip to content

Instantly share code, notes, and snippets.

@RadGH
Last active August 11, 2022 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RadGH/ea41e83399e6c80f7511109c3a804068 to your computer and use it in GitHub Desktop.
Save RadGH/ea41e83399e6c80f7511109c3a804068 to your computer and use it in GitHub Desktop.
Gets a field value from a Gravity Form field, formatted to be compatible with the "gform_field_value" filter (particularly for checkboxes). Replaced with: https://gist.github.com/RadGH/d08a7466b097dfb895ec6dede2e474f5
<?php
// -------------------------------------------------------------------------------------
// Replaced with: https://gist.github.com/RadGH/d08a7466b097dfb895ec6dede2e474f5
//
// Gravity Forms still does not have an official method to get selected checkboxes lmao.
// -------------------------------------------------------------------------------------
/**
* Get the values for a field, compatible with the filter "gform_field_value" particularly for checkbox fields.
*
* Uses the native "get_post_field_value" function which is sadly private (for no good reason).
*
* @see https://stackoverflow.com/a/40441769
*
* @param GF_Field $field
* @param array $lead
*
* @return mixed
*/
function gf_get_field_value_from_entry( GF_Field $field, array $entry ) {
static $formsModel = null, $getValueFn;
if ( $formsModel === null ) {
$formsModel = new GFFormsModel();
$getValueFn = function( $a = null, $b = null ) {
return $this->get_post_field_value( $a, $b );
};
}
return $getValueFn->call( $formsModel, $field, $entry );
}
@RadGH
Copy link
Author

RadGH commented Aug 11, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment