Support » Plugin: Forms: 3rd-Party Integration » Using hooks for XML response

  • Resolved corvusgrp


    Sending xml to a third party using Gravity and Forms: 3rd-Party Integration (also x-post). Works great. Except I am not “getting it”…how do I get the service response to print on the thank you page? the response includes a url which I am to frame into my thank you page. I’ve tried add_action hooks but I am not very experienced with xml and I’m very confused, nothing I do seems to produce any response at all.

    I have confirmed everything is working via debug and vendor’s training tools. If someone could provide a simple explanation and sample code, I’m sure I can get this working.

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


    There’s an example of a hook to change the form message in the FAQ under “How do I show a custom message on the confirmation screen?”, and I wrote another plugin that can interpret an xml response and inject it in the submission.

    Maybe that will point you in the right direction?

    Could you elaborate just a little bit more?

    I’m able to change the success message with a function but struggling to understand how to output the error or failure response message that is, depending on the API, in raw or json format, for example:

    Error: Insert failed, duplicate id

    “instructions”:”Go to your app and enter the given number”

    How would I output that error message or the “instructions” and “number” fields to user?

    Plugin Author zaus



    This worked for me (from 3rd-party Integration Github Issues)
    It’s based on the maybe outdated MailChimp example

    I modified it slightly and added and modified some comments:

    Encapsulate any and all 3rd-party service callback functions
    class Forms3rdParty_Callbacks {
    public function __construct(){
    // actions require 2 parameters: 3rd-party response, results placeholders
    // NOTE: customize this hook name to match your Service (in the admin settings)
    // or use Forms3rdPartyIntegration_service to affect all the forms
    add_action('Forms3rdPartyIntegration_service', array(&$this, 'forms3rdParty_action'), 10, 2);
    }//-- function __construct
    @Param $response the remote-request response
    @Param $results
    public function forms3rdParty_action($response, $results){
    // look once more for success message, in case someone didn't set up the success clause
    if( false !== strpos($response, '"status":"ok"') ) :
    // Decode the received JSON to array
    $response_json = json_decode($response, true);
    //after converting to array output a certain json value (for example "description") to the success message next to the form on page, or whatever it might be in your case
    $results['message'] = 'Success! The response;' $response_json["description"];
    //This is used for adding things to mail (if sent)
    $results['attach'] = $response;
    $results['errors'] = array('Failed');
    } catch(Exception $ex){
    $results['errors'] = array($ex->getMessage());
    }//-- function 3rdParty_action
    }//--- class Forms3rdParty_Callbacks
    //start 'em up
    $Forms3rdPartycallback_instance = new Forms3rdParty_Callbacks();
    endif; //class-exists
    Plugin Author zaus


    Glad that worked. Could you file an issue in GitHub to update that outdated MailChimp example so I can remember to get to it? Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Using hooks for XML response’ is closed to new replies.