Approval of entries in a nested form when the entry in parent form is approved [RESOLVED]

I have a form (Company Particular) with nested form (Attendee Details - could have 1 or multiple attendees). When user submit the form, notification will send to the user and the attendees’ email. However, the confirmation notification will only trigger if the entry is approved. SO I have to approve the entry under both forms.

Is there a way to get nested form entries approved automatically when the parent entry is approved?

Hi Yan,

Unless Gravity Wiz (cc @david) has a code snippet for that, there’s no way to achieve this in GravityView without some custom coding.

watching-couragejd

1 Like

This should be doable with the following:

add_action( 'gravityview/approve_entries/approved', function( $entry_id ) {
	$parent_entry   = GFAPI::get_entry( $entry_id );
	$parent_form    = GFAPI::get_form( $parent_entry['form_id'] );
	$nested_entries = array();

	foreach ( $parent_form['fields'] as $field ) {
		if ( $field instanceof GP_Field_Nested_Form ) {
			$_entries       = explode( ',', $parent_entry[ $field->id ] );
			$nested_entries = array_merge( $nested_entries, $_entries );
		}
	}

	foreach ( $nested_entries as $nested_entry_id ) {
		$nested_entry                = GFAPI::get_entry( $nested_entry_id );
		$nested_entry['is_approved'] = '1';
		GFAPI::update_entry( $nested_entry );
	}
}, 10, 1 );

Quick demo of the snippet: Auto Approve GPNF Nested Entries when a Parent Entry is approved. | Loom

2 Likes

challenge-accepted-yes

3 Likes

Thank you @saifsultanc :pray:

2 Likes

Thanks @saifsultanc. I will try it out.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.