Need to POST xml string to 3rd party api, using gravity forms

I need have a gform submission POST to third party api as xmldata.

Url that data needs to POST to:

XML Format Needed (being pulled from gravity form below):

<crcloud> <lead> <type>Client</type> <firstname>Scott</firstname> <lastname>James</lastname> <client_assigned_to>Bill Smith</client_assigned_to> </lead> </crcloud>
I have a curl function written but I am receiving a parsing error when posting. I have validated the xml and it is correct. I can also paste the xml data that prints out directly behind my url and get the result I want.

add_action(“gform_after_submission”, “set_post_content”, 10, 2);
function set_post_content($entry, $form){

function post_to_url($url, $post) {
    $fields = '';
    foreach($post as $key => $value) {
        $fields .= $key . '=' . $value . '&';
    rtrim($fields, '&');

    $url = ''.$xml;

    $post = curl_init();

    curl_setopt($post, CURLOPT_URL, $url);
    curl_setopt($post, CURLOPT_POST, count($data));
    curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($post, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($post, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($post, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
    curl_setopt($post, CURLOPT_VERBOSE, true);

    $verbose = fopen('php://temp', 'rw+');
    curl_setopt($post, CURLOPT_STDERR, $verbose);

    $result = curl_exec($post);
    echo $post; //Resource id #*** currently
    echo $result; //False 4404 XML parsing error currently

    $verboseLog = stream_get_contents($verbose);
    echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";


if($form["id"] == 2){//sign up now

    $data = array(
        "type" =>     $entry["31"],      
    "firstname" =>     $entry["3"], 
        "lastname" =>     $entry["4"], 
        "client_assigned_to" =>     $entry["34"]); 

    $xml = new SimpleXMLElement('<crcloud/>');
    $lead = $xml->addchild('lead');
    $data = array_flip($data);
    array_walk_recursive($data, array ($lead, 'addChild'));

    print $xml->asXML(); 

    post_to_url($url, $xml); 




Sponsor our Newsletter | Privacy Policy | Terms of Service