Populate nested form field with entries on second page of multi-form [RESOLVED]

I’m hoping someone can offer ideas to the following, any thoughts would be gratefully received:

I have a multi-page form where a user selects an option on page 1 will auto create X number of entries and list in a nested form field on page 2

Using gform_post_paging I can prepare everything, get my data ready to create X entries to go in the nested form field.

The issue I’m having is that the multi-page entry has no ID yet as it hasn’t been saved.
I can create my nested entries using GFAPI::create_entry() but I cannot populate the field ‘GPNF_Entry::ENTRY_PARENT_KEY’ to associate the nested entry with the current multi-page entry been created.

Below is my script with the field in question:

		$new_child_entry = array(
			'form_id' => 123, 
			'created_by' => 1,
			'1' => 'Test',
			GPNF_Entry::ENTRY_PARENT_KEY => 'No Idea what to put here!', 
		$child_entry_id = GFAPI::add_entry( $new_child_entry );

I think that nested form entries generates a temporary ID until an entry is saved - Maybe I need to grab this?

Many thanks in advance


You can get the temporary parent ID with this

$session = new GPNF_Session( $form['id'] );
$cookie  = $session->get_cookie();
$temporary_id = rgar( $cookie, 'hash', '' );

Since the Nested Form field is on page two, the temporary parent entry ID would have been created at the time the snippet is executed so you should get the value from the cookie.

Please give this a try and see if it works for you. If it doesn’t work, then I’ll suggest you get in touch with us via our support form so we can assist further.


1 Like

Perfect - Thank you for your response! :slight_smile:

1 Like