Dynamically Populate Session Hash

Set a field’s dynamic population parameter to “gpnf_session_hash” to populate the current Nested Forms session hash. Works for fields in the parent and child form.

Screenshot: https://gwiz.io/3m9YImu

Code

Filename: gpnf-dyn-pop-session-hash.php

<?php
/**
 * Gravity Perks // Nested Forms // Dynamically Populate Session Hash
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * Set a field's dynamic population parameter to "gpnf_session_hash" to populate the current Nested Forms session hash.
 * Works for fields in the parent and child form.
 *
 * Screenshot: https://gwiz.io/3m9YImu
 */
add_filter( 'gform_field_value_gpnf_session_hash', function( $value, $field ) {
	if ( ! is_callable( 'gp_nested_forms' ) ) {
		return $value;
	}
	if ( gp_nested_forms()->get_parent_form_id() ) {
		$parent_form_id = gp_nested_forms()->get_parent_form_id();
	} else {
		$parent_form_id = $field->formId;
	}
	$session = new GPNF_Session( $parent_form_id );
	return $session->get_runtime_hashcode();
}, 10, 2 );

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.