I need to create an xml packet from a form and then pass that to a web service. They gave me the guildlines to go by to make the XML packet. Below is what I used to make the packet.
//Get Form Variables
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$primaryEmail = $_POST["primaryEmail"];
$streetAddress = $_POST["streetAddress"];
$streetAddressCont = $_POST["streetAddressCont"];
$city = $_POST["city"];
$stateCode = $_POST["stateCode"];
$zipCode = $_POST["zipCode"];
$type = $_POST["type"];
$areaCode = $_POST["areaCode"];
$phoneNumber = $_POST["phoneNumber"];
//Set data to write to file
$Data = "<?xml version='1.0' encoding='UTF-8'?>\n";
$Data = $Data . "<twsRequest remoteId='" . $better_token . "' validateOnly='false'>\n";
$Data = $Data . "<referrer>www.tomjohnsoncamping.com</referrer>\n";
$Data = $Data . "<realm>RVTOL</realm>\n";
$Data = $Data . "<remoteCustomerId>767910</remoteCustomerId>\n";
$Data = $Data . "<messageType>addLead</messageType>\n";
$Data = $Data . "<addLead>\n";
$Data = $Data . "<leadEmail>henryb@tomjohnsoncamping.com</leadEmail>\n";
$Data = $Data . "<source>MY WEBSITE</source>\n";
$Data = $Data . "<standardInfo>\n";
$Data = $Data . "<firstName>" .$firstName. "</firstName>\n";
$Data = $Data . "<lastName>" .$lastName. "</lastName>\n";
$Data = $Data . "<primaryEmail>" .$primaryEmail. "</primaryEmail>\n";
$Data = $Data . "<address>\n";
$Data = $Data . "<streetAddress>" .$streetAddress. "</streetAddress>\n";
$Data = $Data . "<streetAddressCont>" .$streetAddressCont. "</streetAddressCont>\n";
$Data = $Data . "<city>" .$city. "</city>\n";
$Data = $Data . "<stateCode>" .$stateCode. "</stateCode>\n";
$Data = $Data . "<zipCode>" .$zipcode. "</zipCode>\n";
$Data = $Data . "</address>\n";
$Data = $Data . "<phone>\n";
$Data = $Data . "<type>" .$type. "</type>\n";
$Data = $Data . "<areaCode>" .$areaCode. "</areaCode>\n";
$Data = $Data . "<phoneNumber>" .$phoneNumber. "</phoneNumber>\n";
$Data = $Data . "</phone>\n";
$Data = $Data . "</standardInfo>\n";
$Data = $Data . "</addLead>\n";
$Data = $Data . "</twsRequest>\n";
This is how they said to pass the XML packet. Ideas?
function sendRequest($serviceUrl="") {
$postData = "message=" . $this->body; // the XML packet that my earlier email talks about
// use curl to send the request.
$cp = curl_init();
curl_setopt ($cp, CURLOPT_URL, "http://crm.----.com:8080/twsnet/leadService"); // the URL to post to, this is just an example of URL, we will give you a URL when you are ready
curl_setopt ($cp, CURLOPT_POST, 1); // this need to be an html form post.
curl_setopt ($cp, CURLOPT_HEADER, 0); // this need to be an html form post.
//curl_setopt ($cp, CURLOPT_PROXY, TOL_PROXY_SERVER);
curl_setopt($cp, CURLOPT_TIMEOUT, $this->timeout); //times out after X seconds
curl_setopt($cp, CURLOPT_VERBOSE, 1);
curl_setopt($cp, CURLOPT_RETURNTRANSFER,1); // we want the html of the request returned into the variable.
curl_setopt($cp, CURLOPT_POSTFIELDS, $postData); // set the form fields.
$this->rawResponse = curl_exec($cp);
curl_close($cp);
$this->parseResponse($this->rawResponse);
if ($this->response['code'] == "SUCCESS") {
return true;
} else {
return false;
}
}
I did this with that code...
$postData = "message=" . $Data; // the XML packet that my earlier email talks about
// use curl to send the request.
$cp = curl_init();
curl_setopt ($cp, CURLOPT_URL, "http://crm.----.com:8080/twsnet/leadService"); // the URL to post to, this is just an example of URL, we will give you a URL when you are ready
curl_setopt ($cp, CURLOPT_POST, 1); // this need to be an html form post.
curl_setopt ($cp, CURLOPT_HEADER, 0); // this need to be an html form post.
//curl_setopt ($cp, CURLOPT_PROXY, TOL_PROXY_SERVER);
curl_setopt($cp, CURLOPT_TIMEOUT, '30'); //times out after X seconds
curl_setopt($cp, CURLOPT_VERBOSE, 1);
curl_setopt($cp, CURLOPT_RETURNTRANSFER,1); // we want the html of the request returned into the variable.
curl_setopt($cp, CURLOPT_POSTFIELDS, $postData); // set the form fields.
curl_exec($cp);
curl_close($cp);
And did not make it a function. Just let run run right after I set $Data