Loading data into a nested form without in being submitted

I am trying to load data into a nested form via an ACF Repeater. I’ve hacked together a few different snippets. I know I have pulling data from ACF correct via the loop. But I cannot figure out how to get the data into the child form. I believe the two parts missing is getting the entry ID, and how to trigger the function correctly. I am doing this all with Snippet editor.

function populate_member_child_form() {
	//get parent entry form ID
	$session = new GPNF_Session( $form['88'] );
	$cookie  = $session->get_cookie();
	$temporary_id = rgar( $cookie, 'hash', '' );
	$userid = get_current_user_id();
	$household = get_field('household_members', 'user_'.$userid );
	foreach( $household as $person) {
		$new_child_entry = array(
    		'form_id' => 87, // The ID of the child form.
    		'created_by' => $userid,
			'2' => $person['date_of_birth'], // DoB
    		'1.3' => $person['member_first_name'], //member_first_name
    		'1.6' => $person['member_last_name'], //member_last_name
    		'4' => $person['member_phone_numer'], //member_phone_number
			'3' => $person['member_email_address'], //member_email_address
    		GPNF_Entry::ENTRY_PARENT_KEY => $temporary_id, // The ID of the parent entry.
    		GPNF_Entry::ENTRY_PARENT_FORM_KEY => 88, // The ID of the parent form.
    		GPNF_Entry::ENTRY_NESTED_FORM_FIELD_KEY => 4, // The ID of the Nested Form field on the parent form.
	$child_entry_id = GFAPI::add_entry( $new_child_entry );

add_filter( 'gpnf_init_nested_form', 'populate_member_child_form' );

Hi Adam,

You can trigger the function using the gform_pre_render hook of the parent form, but I am unsure if it will work for your use case. I see you already have a ticket with us at Gravity Wiz, with the same question, so one of our developers will contact you via email with further answers so your questions.


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