Filter Child Form to Only Show Summary Fields

Instructions

Code

Filename: gpnf-only-show-summary-fields.php

<?php
/**
 * Gravity Perks // Nested Forms // Filter Child Form to Only Show Summary Fields
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * Instruction Video: https://www.loom.com/share/fa476785344a4bbe9ac377793812f534
 */
add_filter( 'gform_pre_render', 'gpnf_filter_child_form_by_summary_fields' );
add_filter( 'gform_pre_process', 'gpnf_filter_child_form_by_summary_fields' );
function gpnf_filter_child_form_by_summary_fields( $form ) {

	if ( ! is_callable( 'gp_nested_forms' ) ) {
		return $form;
	}

	$parent_form_id = rgar( $_REQUEST, 'gpnf_parent_form_id' );
	if ( ! $parent_form_id ) {
		return $form;
	}

	$nested_form_field = GFAPI::get_field( GFAPI::get_form( $parent_form_id ), rgar( $_REQUEST, 'gpnf_nested_form_field_id' ) );
	if ( $form['id'] != $nested_form_field->gpnfForm ) {
		return $form;
	}

	$filtered_fields = array();
	foreach ( $form['fields'] as $field ) {
		if ( in_array( $field->id, $nested_form_field->gpnfFields ) ) {
			$filtered_fields[] = $field;
		}
	}

	$form['fields'] = $filtered_fields;

	return $form;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.