Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spivurno/dc6ef3b95c904cf05577e5677d6c4952 to your computer and use it in GitHub Desktop.
Save spivurno/dc6ef3b95c904cf05577e5677d6c4952 to your computer and use it in GitHub Desktop.
<?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