Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matty0501/d489505eb676cabe01b53aa1f330ecb7 to your computer and use it in GitHub Desktop.
Save matty0501/d489505eb676cabe01b53aa1f330ecb7 to your computer and use it in GitHub Desktop.
<?php
/**
* Gravity Wiz // Nested Forms // Populate Parent Entry ID in Child Entry
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
*
* Populate the parent entry ID into a field in the child entry upon submission of the parent form.
*/
add_action( 'gform_after_submission_123', function( $entry, $form ) { // Replace 123 with your parent form ID
$parent_entry = new GPNF_Entry( $entry );
$parent_id = rgar( $entry, 'id' );
$child_entries = $parent_entry->get_child_entries( $nested_form_field_id );
foreach( $child_entries as $child ){
$child_id = rgar( $child, 'id' );
GFAPI::update_entry_field( $child_id, 9, $parent_id ); // Replace 9 with the field ID that you want to populate in the child form
}
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment