Get Nested Form Entry Value or Count Repeater (Beta) number of rows and calculate [RESOLVED]

I have 2 forms namely Charity Donation with Form ID 20 and Items with Form ID 21.
The Charity Donation Form consist of a lot of fields including Organization/Name, Phone number and a whole lot of fields and most importantly a nested form field with ID 32 which is linked to the Items Form (ID 21) that consist of just one single line text field with ID 9.

-Nested Form-
I’m able to put all other values using the $entry[‘Field ID’] but nested form field returns only the entry id instead of the entry value.

-Repeater (Beta)-
I tried using Repeater (Beta), I’ve created the field but there some of the item that includes an amount, Is there a way to assign price to each row Repeater (Beta) then use the total field to multiple the rows added use the total field get the amount money received per row. Thanks in advance

Hi Nana,

Regarding Nested Forms you can access the child form entries like this;

$parent_entry = new GPNF_Entry( $entry );
$child_entries = $parent_entry->get_child_entries( $nested_form_field_id );

You can then loop through the $child_entries array to get the values of each entry.

I hope this helps.

Best,

Hello, Samuel thanks for stopping by to respond my thread i really appreciate it man!, By the way are you a Ghanaian you have our accent (in this video) :slightly_smiling_face: .

I managed to get the value via CGPT later on code below, But the problem i’m facing now is assuming you add one or just 2 items to the nested form, The xml sent to our parent web service about 19 more previous items that’s been submitted via the nested form will be included in the xml, Why?

add_action('gform_after_submission_65', 'test_to_third_party', 10, 3);
function test_to_third_party($entry, $form, $entry_id)
{
    if (rgpost('gform_submit') != $entry['form_id']) {
        return;
    }

    $url      = 'IP Address';
    $encoding = 'UTF-8';
    $username    = htmlspecialchars("Organization Name", ENT_XML1, $encoding);
    $password  = htmlspecialchars("cc@2441123", ENT_XML1, $encoding);
    $org_num  = htmlspecialchars("77889900", ENT_XML1, $encoding);
    $org_pin    = htmlspecialchars($entry['6'], ENT_XML1, $encoding);

    // Get the nested form entries
    $nested_form_entries = GFAPI::get_entries([
        'form_id' => 66,
        'entry_meta' => [
            'parent_entry_id' => $entry_id
        ]
    ]);

    foreach ($nested_form_entries as $nested_entry) {
        $item_list = '';
        $item_entry_id = rgar($nested_entry, 'id');

        // Get the items from the nested entry
        if ($item_entry_id) {
            $item_entry = GFAPI::get_entry($item_entry_id);
            if ($item_entry) {
                $item_list = rgar($item_entry, '9');
                $donaterkey = $nested_entry['10'];
            }
        }

        $products = htmlspecialchars($item_list, ENT_XML1, $encoding);

        $xml = "<?xml version=\"1.0\" encoding=\"$encoding\"?>
		<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">		
			<soapenv:Header/>
			<soapenv:Body>
				<tem:CharityBuild>
					<tem:username>$username</tem:username>
					<tem:password>$password</tem:password>
					<tem:org_num>$org_num</tem:org_num>
					<tem:products>$products</tem:recipientMsisdn>
					<tem:salt_key>$donaterkey</tem:salt_key>
					<tem:org_pin>$org_pin</tem:org_pin>
				</tem:CharityBuild>
			</soapenv:Body>
		</soapenv:Envelope>";
		
        // Log the XML request
        $xml_log = "XML Request: \n" . $xml . "\n\n";
        error_log($xml_log, 3, $_SERVER['DOCUMENT_ROOT'] . '/temp_review.txt');

		// Set up the cURL request
		$ch = curl_init($url);
		if ($ch === false) {
			throw new RuntimeException("cURL initialization failed: " . curl_error());
		}

		$result = curl_setopt_array($ch, [
			CURLOPT_POST => 1,
			CURLOPT_HTTPHEADER => ['Content-Type: text/xml'],
			CURLOPT_CUSTOMREQUEST => 'POST',
			CURLOPT_POSTFIELDS => $xml,
			CURLOPT_RETURNTRANSFER => 1,
			CURLOPT_URL => $url,
			CURLOPT_RETURNTRANSFER => 1,
			CURLOPT_SSL_VERIFYHOST => 0,
			CURLOPT_SSL_VERIFYPEER => 0,
		]);

		if ($result === false) {
			throw new RuntimeException("cURL options failed: " . curl_error($ch));
		}

		// Execute the cURL request
		$output = curl_exec($ch);

		if ($output === false) {
			throw new RuntimeException("cURL request failed: " . curl_error($ch));
		}

		// Close the cURL request
		curl_close($ch);
	
	}

}

Hi Nana,

Yes, I am Ghanaian😅. You’re welcome. The solution you’re using with GFAPI appears to be querying the entire entries for the Nested form entries. Can you try the solution I suggested earlier and see if it works for you;

$parent_entry = new GPNF_Entry( $entry );
$nested_form_entries = $parent_entry->get_child_entries( 32 );

This should get only the Nested forms entries for the current parent entry submitted.

So replace this line of code below with what’s above;

// Get the nested form entries
$nested_form_entries = GFAPI::get_entries([
‘form_id’ => 66,
‘entry_meta’ => [
‘parent_entry_id’ => $entry_id
]
]);

Best,

It worked like charm, Thanks once again Bro.

1 Like