views:

574

answers:

4

Hello all,

I have this form that I am trying to use to post data to an external url. I do have some very basic knowlegde of using php curl. So far if I use this code that I have written:

<?php
    if ($_POST['request_callback'])
    {
      $customer_name = cleaninput($_REQUEST['customer_name'],"text");
      $debtor_id = cleaninput($_REQUEST['debtor_id'],"number");
      $telephone_number = cleaninput($_REQUEST['customer_number'],"number");

      if ($_POST['callme_now'] == '1') {
         $callback_time = date('y-m-d ' . $_POST['hour_select'] . ':' . $_POST['minute_select'] . ':s');
      } else {
         $callback_time = date('y-m-d H:i:s');
      }

      // Send using CURL 
      $ch = curl_init(); 
      curl_setopt( $ch, CURLOPT_URL, "http://www.myjoomla.eo/test.php"); // URL to post 
      curl_setopt ($ch, CURLOPT_POST, 1);
      curl_setopt ($ch, CURLOPT_POSTFIELDS,         "Name=$customer_name&Debtor_ID=$debtor_id&Telephone_Number=$telephone_number&CallBack_Time=$callback_time");
      curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
      $result = curl_exec( $ch ); // runs the post 
      curl_close($ch);
      echo "Reply Response: " . $result; // echo reply response
     }
?>

So far, it does post to the file and the results are display. Now how do I format the data that has been posted into xml format? Ideally, I am trying to acheive something like this an xml that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<CallRequest>
<ProjectName>Test</ProjectName>
<ContactNumberToDial>07843088348</ContactNumberToDial>
<DateTimeToDial></DateTimeToDial>
<ListSource>WebLead</ListSource>
<AgentName></AgentName>
<AddToList>False</AddToList>
<SpecificAgent>False</SpecificAgent>
<DBField>
    <FieldName>Name</FieldName>
    <FieldValue>Testing</FieldValue>
</DBField>
</CallRequest>

Anyone have an Idea of what to do here?

Thanks,

James

+1  A: 

Hey James,

An XML library I have used in the past that allows you to create XML using PHP is XmlWriter. This library was originally written to work with PHP4. You'll find that its name conflicts with that of a built-in PHP5 class so you'll need to change both the class declaration and the constructor to something else.

Hope that helps!

jkndrkn
A: 

Hey James,

I agree with jkndrkn - it seems cURL is correct, it's a matter of the output from test.php. IBM has a great article about reading/writing/parsing XML with PHP, check it out here.

Bill Huertas
A: 
James
A: 

did you get this to work?

mandm