• I feel like I’m overlooking something very simple here, but I have Gravity Forms setup to post to a 3rd party API, which I setup.

    When the plugin is in test/debug mode and I view the email that is created and sent to me everything is working perfectly and in the email I’m seeing the response from the API in the body.

    I can’t figure out how to display that response in the page in WordPress.

    When I submit the Gravity Form I have Gravity Forms send me back to the same page because I want the form to still be available to make more requests to the API, but I want the response from the request to be displayed under my form. However, I can’t figure out how to get access to the response on this page.

    What is the process for sending an API request and displaying the response under the form on that page? Nothing from a $_POST or $_GET is available to me on the page after submission, yet the response is coming back just fine in the test email.

    Thanks for your help

    https://www.ads-software.com/plugins/forms-3rdparty-integration/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author zaus

    (@zaus)

    Have you tried the suggestion under “How do I show a custom message on the confirmation screen?” on https://www.ads-software.com/plugins/forms-3rdparty-integration/faq/?

    I’m having the same issue – i’ve seen many threads started on this.

    when i post to a service, i can see the response in the debug email, yet I want the response to be what the end user sees. I’ve seen ways to make a custom confirmation message, yet i want the response to be the actual body output of the service response

    Also – i’m online now and can actively work with you to figure out a hook for this

    posisbly something to do with gform_confirmation
    possibly a way to return $response from the service?

    Plugin Author zaus

    (@zaus)

    As I said, have you tried what I wrote in the faq?

    How do I show a custom message on the confirmation screen?
    The failure message is shown by default if the 3rdparty post did not succeed. You can add custom messaging to the plugin’s (GF, CF7, Ninja) email or success screen response with something like:

    class MyPlugin {
        public function MyPlugin() {
            add_filter('Forms3rdPartyIntegration_service', array(&$this, 'adjust_response'), 10, 2);
        }
    
        public function adjust_response($body, $refs) {
            // use 'attach' to inject to regular email
            // use 'message' to inject to page
            $refs['attach'] = 'custom message in email';
            $refs['message'] = 'custom message on page'; // <---- this
        }
    }
    new MyPlugin(); // attach hook
    

    You have access to the response $body in the hook.

    Maybe I need to word it differently –
    Can the body of the response become the body the browser becomes?
    For example, I have a form that starts a free trial of an application, when you fill out the form it automatically logs you in (user goes from submitting form on sitea, to being logged in on siteb). If I post directly as action=”xyz.com/activate/” it performs this action properly, yet i lose the benefits of gravity.

    What if the $body of the response saved to an object buffer?
    then the object buffer could create a temporary html file
    once html file is created by the object buffer, <?php header(tempobjectbufferdump.html) ?> within the custom confirmation? header or __top there has to be some way to achieve this

    Plugin Author zaus

    (@zaus)

    Ohhh…I get it, sorry; like a redirect.

    I’m not entirely sure, as php doesn’t really have a way to clear the output buffer unless you’ve already started it (https://php.net/manual/en/function.ob-end-clean.php), but depending on when wp actually writes the page compared to when the hooks run, you might be able to just echo the service response and tell php to exit. You might need to save the response to a temp variable and do the writing/exit in a later hook to give GF a chance to finish its processing.

    But that might not even work for your purposes if you need the associated cookies and stuff.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Displaying response from 3rd party using Gravity Forms’ is closed to new replies.