Gform_confirmation rgar($entry, "1") [RESOLVED]

Hello,

I am using add_action(‘gform_confirmation_3’, array($this, ‘custom_confirmation’), 10, 4); in a plugin to send form data to a 3rd party api and show the response in the confirmation. I have everything set up, but my entry is empty. When I error log the body the values are empty. Am I using the rgar() wrong? I’m passing in the field id value. Each of these fields are either text or dropdown fields. Ajax is set to true on the form. Not sure what else I may be missing. Any help would be appreciated!

    function custom_confirmation($confirmation, $entry, $form, $ajax) {
//emptied get token function from here as it's not important to the info below
        // Use Token In Actual Call
        $post_url = $token['instance_url'] . '/services/apexrest/FindAccountRepService/V1';
        $args = array(
            'acctInfo' => array(
                'name' => rgar( $entry, '1' ),
                'country' => rgar( $entry, '10' ),
                'postalCode' => rgar( $entry, '7' ),
                'state' => rgar( $entry, '9' ),
                'city' => rgar( $entry, '8' ),
                'productLine' => rgar( $entry, '4' ),
                'industryType' => rgar( $entry, '5' )
            )
        );
        $body = json_encode($args);

        error_log(print_r($body, true));

        GFCommon::log_debug( 'gform_confirmation: body => ' . print_r( $body, true ) );
     
        $request  = new WP_Http();
        $response = $request->post( $post_url, array( 
            'headers' => array(
                'Authorization' => $token['token_type'] . ' ' . $token['access_token'],
                'Cookie'        => 'BrowserId=unsAxTdPEeyddq_3TSkKyg; CookieConsentPolicy=0:0; LSKey-c$CookieConsentPolicy=0:0',
                'Content-Type'  => 'application/json'
            ),
            'body' => $body ) 
        );

        GFCommon::log_debug( 'gform_confirmation: response => ' . print_r( $response, true ) );
        $confirmation .= print_r( $response, true );
        return $confirmation;
    }

At first glance a couple things stand out to me:

  • gform_confirmation is a filter, not an action. You’d use add_filter(), not add_action()
  • Your parameters in the callback function are a little crossed up. As the filter doc notes the entry object is the third parameter available with the filter, but you’re trying to get the entry from the second in your code. With how your function is declared $form would be the entry object and $entry would be the form object in the context of your function.
3 Likes

Wow, thanks, I totally missed that. I just changed those two things and it’s working now. You’re the best!

2 Likes

First off…Love the username @fairlypainless…Reminds me of Hitchhikers Guide to the Galaxy view of humans as Mostly Harmless :slight_smile:

If you are looking to setup more API calls where the value for display wants to be in confirmation, notification or used in fields later in any of your exports or business processes, there is a fairly painless (read no code) approach you could consider with Gravity Flow’s outgoing webhook step and its’ response mapping settings. Here’s a similar forum post answer where I showed the step settings, confirmation use of merge tag for the field value, etc.

Cheers,
Jamie

2 Likes