gppa_input_choice

  1. Description
  2. Usage
  3. Parameters
  4. Since
  5. Examples
    1. Add a custom choice template to choices

Description

Modify the current choice that’s being populated into the current field.

Usage

Apply to all fields on all forms.

add_filter( 'gppa_input_choice', 'my_custom_function' );

Apply to all fields on a specific form.

add_filter( 'gppa_input_choice_FORMID', 'my_custom_function' );

Apply to a specific field on a specific form.

add_filter( 'gppa_input_choice_FORMID_FIELDID', 'my_custom_function' );

Parameters

  • choice array

    The current choice being populated.

  • field \GF_Field

    The current field being populated.

  • object array

    The current object being populated into the current choice.

  • objects array

    An array of objects being populated as choices into the field.

Since

This filter is available since Gravity Forms Populate Anything 1.0-beta-4.116.

Examples

Add a custom choice template to choices

Add a choice template named image to choices. This pairs well with the gppa_template_rows JavaScript filter.

<?php
/**
 * Gravity Perks // Populate Anything // Add A Custom Choice Template
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 *
 * Choice templates allow you to map data to different properties of your Gravity Forms choices.
 *
 * In this example, we demonstrate how to create a new template for a theoretical "image" choice property.
 * With this in place, you would be able to select a value in the Populate Anything choices UI that is
 * mapped to the "image" property for each choice.
 */
add_action( 'admin_print_footer_scripts', function () {
	if ( ! is_callable( 'GFCommon::is_form_editor' ) || ! GFCommon::is_form_editor() ) {
		return;
	}
	?>
	<script>
	window.gform.addFilter( 'gppa_template_rows', function (templateRows, field, populate) {
		if ( populate !== 'choices' ) {
			return templateRows;	
		}
		templateRows.push( {
			id: 'image',
			label: 'Image',
		} );
		return templateRows;
	} );
	</script>
	<?php
} );

add_filter( 'gppa_input_choice', function( $choice, $field, $object, $objects ) {
	$choice['image'] = gp_populate_anything()->process_template( $field, 'image', $object, 'choices', $objects );
	return $choice;
}, 10, 4 );