Last active
February 9, 2021 20:18
-
-
Save spivurno/dc6ef3b95c904cf05577e5677d6c4952 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gravity Perks // Nested Forms // Force {Parent} Merge Tag Replacement on Submission | |
* http://gravitywiz.com/documentation/gravity-forms-nested-forms/ | |
*/ | |
add_filter( 'gform_entry_post_save', function( $entry, $form ) { | |
foreach( $form['fields'] as &$field ) { | |
if( $field->get_input_type() == 'form' ) { | |
$child_form_id = $field->gpnfForm; | |
$child_form = GFAPI::get_form( $child_form_id ); | |
foreach( $child_form['fields'] as $child_field ) { | |
preg_match( '/{Parent\:(.+)}/i', $child_field->defaultValue, $match ); | |
if( $match ) { | |
$value = rgar( $entry, $match[1] ); | |
$child_entry_ids = explode( ',', rgar( $entry, $field->id ) ); | |
foreach( $child_entry_ids as $child_entry_id ) { | |
GFAPI::update_entry_field( $child_entry_id, $child_field->id, $value ); | |
} | |
} | |
} | |
} | |
} | |
return $entry; | |
}, 11, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php