Capture Nested Form Field Label in Child Form

This snippet allows you to capture the label of the Nested Form field from which the child form has been opened.

This is useful when you have two or more Nested Form fields on the same parent form, using the same child form and need to identify to which Nested Form field the child entry belongs (e.g. Team Captains vs Players).

Instructions

  1. Install the snippet. https://gravitywiz.com/documentation/managing-snippets/#where-do-i-put-snippets

  2. Enable dynamic population on your desired field on the child form.

  3. Set the dynamic population parameter to “gpnf_nested_form_field_label”.

Code

Filename: gpnf-capture-nested-form-field-label.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
 * Gravity Forms // Nested Forms // Capture Nested Form Field Label in Child Form
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * Instruction Video: https://www.loom.com/share/1630b49c960441e8a5d13b0d5c2fa3e8
 *
 * This snippet allows you to capture the label of the Nested Form field from which the child
 * form has been opened.
 *
 * This is useful when you have two or more Nested Form fields on the same parent form, using
 * the same child form and need to identify to which Nested Form field the child entry belongs
 * (e.g. Team Captains vs Players).
 *
 * Instructions:
 *
 * 1. Install the snippet.
 *    https://gravitywiz.com/documentation/managing-snippets/#where-do-i-put-snippets
 * 
 * 2. Enable dynamic population on your desired field on the child form.
 *
 * 3. Set the dynamic population parameter to "gpnf_nested_form_field_label".
 */
add_filter( 'gform_field_value_gpnf_nested_form_field_label', function () {

	// Get the parent form ID
	$form_id = gp_nested_forms()->get_parent_form_id();
	if ( ! $form_id ) {
		return '';
	}

	// Retrieve the form object
	$form = GFAPI::get_form( $form_id );
	if ( ! $form ) {
		return '';
	}

	// Get the posted Nested Form field ID
	$nested_form_field_id = rgar( $_REQUEST, 'gpnf_nested_form_field_id' );
	if ( ! $nested_form_field_id ) {
		return '';
	}

	// Get the Nested Form field object
	$nested_form_field = GFFormsModel::get_field( $form, $nested_form_field_id );
	if ( ! $nested_form_field || ! is_object( $nested_form_field ) ) {
		return '';
	}

	// Return the field label
	return $nested_form_field->get_field_label( false, '' );
} );

Comments

  1. Robert Adrichem
    Robert Adrichem March 19, 2026 at 10:17 am

    Perfect solution! Actually, I use it in an hour registration form where each day of the week has its own nested field . Now I can automatically add the day of the week based on the used nested field in the child form.

    Reply
    1. Matt Andrews
      Matt Andrews Staff March 19, 2026 at 10:53 am

      Hi Robert,

      That sounds like a great use case for this snippet. I’m happy to hear it’s working well for you! 😁

      Best,

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.