Page 1 of 1

XML Post in PHP

Posted: Thu Apr 08, 2010 3:05 pm
by bhaynes
I'm trying to post an xml request within a php file. I'm taking form data submitted by a user and reading them into php variables. Then I'm inserting those variables into the xml and trying to post via javascript. I keep receiving the following error: Only one top level element is allowed in an XML document. Error processing resource 'http://seniorsretirement.com/preview/r...
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
-^

Any help would be appreciated!

Here's the complete PHP code:

<?php

header("Content-type:text/xml; charset=utf-8");

$VenderLeadDate = strftime("%m/%d/%Y");

$Inquiring = urlencode($_POST['Inquiring']);
$FirstName = urlencode($_POST['FirstName']);
$LastName = urlencode($_POST['LastName']);
$Gender = urlencode($_POST['Gender']);
$HomePhone = urlencode($_POST['HomePhone']);
$Email = urlencode($_POST['Email']);
$BestTimeToContact = urlencode($_POST['BestTimeToContact']);
$HomeownerAge = urlencode($_POST['HomeownerAge']);
$SpouseAge = urlencode($_POST['SpouseAge']);
$PropertyType = urlencode($_POST['PropertyType']);
$PropertyAddress1 = urlencode($_POST['PropertyAddress1']);
$PropertyCity = urlencode($_POST['PropertyCity']);
$PropertyState = urlencode($_POST['PropertyState']);
$PropertyZipCode = urlencode($_POST['PropertyZipCode']);
$PropertyMarketValue = urlencode($_POST['PropertyMarketValue']);
$MortgageBalance1 = urlencode($_POST['MortgageBalance1']);

$Address1 = urlencode($_POST['Address1']);
$Address2 = urlencode($_POST['Address2']);
$City = urlencode($_POST['City']);
$State = urlencode($_POST['State']);
$ZipCode = urlencode($_POST['ZipCode']);
$LoanPurpose = $_REQUEST["LoanPurpose"];
$LoanAmount = $_REQUEST["LoanAmount"];
$VenderLeadPrice = $_REQUEST["VenderLeadPrice"];
$CustomerIp = $_REQUEST["CustomerIp"];
$VenderID = $_REQUEST["VenderID"];
$Password = $_REQUEST["Password"];
$OrganizationID = $_REQUEST["OrganizationID"];

if ($State == "" || $State == "0"){
$State = $PropertyState;
}

if ($PropertyState == "" || $PropertyState == "0"){
$PropertyState = $State;
}

echo"
<Lead xmlns='http://tempuri.org/Lead.xsd'>
<InquiringOnBehalfOf>$Inquiring</InquiringOnBehalfOf>
<FirstName>$FirstName</FirstName>
<MiddleName></MiddleName>
<LastName>$LastName</LastName>
<Age>$HomeownerAge</Age>
<GovtMonitoringSex>$Gender</GovtMonitoringSex>
<Address1>$Address1</Address1>
<Address2>$Address2</Address2>
<City>$City</City>
<State>$State</State>
<ZipCode>$Zipcode</ZipCode>
<Email>$Email</Email>
<HomePhone>$HomePhone</HomePhone>
<WorkPhone></WorkPhone>
<WorkPhoneExt></WorkPhoneExt>
<CellPhone></CellPhone>
<Fax></Fax>
<SSN></SSN>
<CoFirstName>$CoFirstName</CoFirstName>
<CoMiddleName></CoMiddleName>
<CoLastName>$CoLastName</CoLastName>
<CoAge>$SpouseAge</CoAge>
<CoGovtMonitoringSex></CoGovtMonitoringSex>
<CoAddress1></CoAddress1>
<CoAddress2></CoAddress2>
<CoCity></CoCity>
<CoState></CoState>
<CoZipCode></CoZipCode>
<CoEmail></CoEmail>
<CoHomePhone></CoHomePhone>
<CoWorkPhone></CoWorkPhone>
<CoWorkPhoneExt></CoWorkPhoneExt>
<CoCellPhone></CoCellPhone>
<CoFax></CoFax>
<CoSSN></CoSSN>
<BestTimeToContact>$BestTimeToContact</BestTimeToContact>
<EstimatedCredit>0</EstimatedCredit>
<LoanPurpose>$LoanPurpose</LoanPurpose>
<LoanAmount>$LoanAmount</LoanAmount>
<PropertyType>$PropertyType</PropertyType>
<PropertyUse>0</PropertyUse>
<PropertyOccupancyType>0</PropertyOccupancyType>
<PropertyMarketValue>$PropertyMarketValue</PropertyMarketValue>
<PropertyAddress1></PropertyAddress1>
<PropertyAddress2></PropertyAddress2>
<PropertyCity></PropertyCity>
<PropertyState></PropertyState>
<PropertyZipCode></PropertyZipCode>
<MortgageHolder1></MortgageHolder1>
<MortgageBalance1>$MortgageBalance1</MortgageBalance1>
<MortgagePayment1>0</MortgagePayment1>
<MortgageRate1>0</MortgageRate1>
<MortgageClassification1>0</MortgageClassification1>
<MortgageHolder2></MortgageHolder2>
<MortgageBalance2>0</MortgageBalance2>
<MortgagePayment2>0</MortgagePayment2>
<MortgageRate2>0</MortgageRate2>
<MortgageClassification2>0</MortgageClassification2>
<VendorLeadDate>$VenderLeadDate</VendorLeadDate>
<VendorLeadPrice>$venderLeadPrice</VendorLeadPrice>
<VendorLeadId></VendorLeadId>
<VendorCampaign></VendorCampaign>
<CustomerIp>$CustomerIp</CustomerIp>
<VendorWebProperty></VendorWebProperty>
<VendorCreative></VendorCreative>
<VendorKeywords></VendorKeywords>
<CurrentLoanStatus></CurrentLoanStatus>
<VendorId>$VenderID</VendorId>
<Password>$Password</Password>
<OrganizationId>$OrganizationID</OrganizationId>
<OpportunityId>2</OpportunityId>
<IsTestLead>0</IsTestLead>
</Lead>

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/'>
<!-- you java script coding will start here -->
<xsl:text disable-output-escaping='yes'>
<![CDATA[
<script>
var xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
xmlhttp.open('POST', 'http://24.184.81.114:5403/ITLLeadImportXML.aspx', false);
xmlhttp.send();
alert(xmlhttp.ResponseText);
</script>
]]>
</xsl:text>
<!-- javascripting ends -->
<!-- your xsl code -->
......
</xsl:template>
</xsl:stylesheet>
";

$message = "<FONT FACE='Arial, Tahoma, Verdana'>
Reverse Mortgage Request
Source: SeniorsRetirement.com
Date: $VenderLeadDate
Exclusivity: False
<br><br>
House Type: $PropertyType<br>
House Value: $PropertyMarketValue<br>
Mortgage Balance: $MortgageBalance1
<br><br>
Contact Info:<br>
Name: $FirstName $LastName<br>
Email: $Email<br>
Phone: $HomePhone<br>
Address:<br>
$Address1<br>
$Address2<br>
$City<br>
$State<br>
$ZipCode
<br><br>
Applicant Info:<br>
HomeownerAge: $HomeownerAge<br>
State: $State<br>
Zip: $ZipCode<br>
Gender: $Gender<br>
<br><br>
Spouse:<br>
Name: $CoFirstName $CoLastName<br>
Age: $SpouseAge
<br><br>
NOTE: THIS IS A CONFIDENTIAL COMMUNICATION. This transmission is intended only for the use of the individual(s) to which it is addressed. If you are not the intended recipient, or the person responsible for delivering this message to the intended recipient, please reply immediately and delete and destroy all copies of this message. This e-mail and any attachments are believed to be free of any virus or other defect. It is the responsibility of the recipient to ensure that it is virus-free and no responsibility is accepted by us for any loss or damage arising in any way from its unauthorized modification or use.
</font>
";

mail("leads@upstatecapital.com", "Request from $Name", $message,
"From: SeniorsRetirement.com <leads@upstatecapital.com>\r\n" .
"Reply-To: SeniorsRetirement.com <leads@upstatecapital.com>\r\n" .
"Content-type: text/html; charset=us-ascii");

include("request-thanks.php?State=$PropertyState");

?>

Re: XML Post in PHP

Posted: Thu Apr 08, 2010 4:11 pm
by minorDemocritus
Please enclose code blocks in [ syntax=php ][ /syntax ] bbcode so it's easier to read.

I'm not that familiar with XML, but it appears the source of the error is that you have 2 top level elements: <Lead> and <xsl:stylesheet>

Also, you should check to make sure something has actually been posted to the script before attempting to assign variable to values stored in the $_POST array. Use something like:

Code: Select all

if (isset($_POST['Inquiring']) {
    // assign variables
}
You should also probably do some sort of input validation as well.