Attach Child Entry to Parent Programmatically

Code

Filename: gpnf-attach-child-entry-programatically.php

<?php
/**
 * Gravity Perks // Nested Forms // Attach Child Entry to Parent Programmatically
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 */
// Update "124" to your child form ID.
add_filter( 'gform_entry_post_save_124', function( $entry ) {
	$entry = array_replace( array(
		// The ID of the parent entry.
		GPNF_Entry::ENTRY_PARENT_KEY            => 234,
		// The ID of the parent form.
		GPNF_Entry::ENTRY_PARENT_FORM_KEY       => 123,
		// The ID of the Nested Form field on the parent form.
		GPNF_Entry::ENTRY_NESTED_FORM_FIELD_KEY => 4,
	), $entry );
	GFAPI::update_entry( $entry );
	return $entry;
} );

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.