Talk:Postal Address Verification

From CDYNE Wiki
Jump to: navigation, search

The CDYNE address verification system works great using PHP! Check below on how to implement it on your site. Must be using PHP5 to use the xmlparser code.

<?php
# INTITAL VARIABLE
# INSERT LICENSE KEY BELOW
$license_key = "put license key here";
 
# GRAB FORM FIELDS FROM PREVIOUS FORM THESE WILL CHANGE DEPENDENT ON YOUR FORM
$name = $_POST['NameFirst'] . " " . $_POST['NameLast'];
$apt = urlencode($_POST['apt']);
$address = urlencode($_POST['Address']);
$city = urlencode($_POST['City']);
$state = urlencode($_POST['State']);
$zip = urlencode($_POST['ZipCode']);
$phone = $_POST['Phone'];
$email = $_POST['EMail'];
$HowDidYouHear = $_POST['HowDidYouHear'];
 
 
# EXECUTE THE CONNECTION TO CYDNE
$url = "http://ws.cdyne.com/psaddress/addresslookup.asmx/AdvancedCheckAddress?AddressLine=$address&AddressLine2$apt=&ZipCode=$zip&City=$city&StateAbbrev=$state&LicenseKey=$license_key";
 
//Since we're already using PHP5, USE THE FILE_GET_CONTENTS
$xmlFileData = file_get_contents($url);
 
//Here's our Simple XML parser!
$xmlData = new SimpleXMLElement($xmlFileData);
 
// VALIDATION RESULTS
$xmlAddressError = $xmlData->anyType[0]->AddressError;
$xmlDeliveryAddress = $xmlData->anyType[0]->DeliveryAddress;
$xmlCity = $xmlData->anyType[0]->City;
$xmlStateAbbrev = $xmlData->anyType[0]->StateAbbrev;
$xmlZipCode = $xmlData->anyType[0]->ZipCode;
 
echo $xmlAddressError . "<BR>";
echo $xmlDeliveryAddress . "<BR>";
echo $xmlCity . "<BR>";
echo $xmlStateAbbrev . "<BR>";
echo $xmlZipCode . "<BR>";
 
// ####################################
// # PRESENT TO CLIENT
// ####################################
if ($xmlAddressError == "false") {
echo "ADDRESS IS CORRECT:" . "<BR>";
echo $address . "<BR>";
echo $city . "<BR>";
echo $state . "<BR>";
echo $zip . "<BR>";
}
else {
echo "ADDRESS NOT FOUND:" . "<BR>";
echo $address . "<BR>";
echo $city . "<BR>";
echo $state . "<BR>";
echo $zip . "<BR>";
}
 
 
 
 
?>
Personal tools
Namespaces

Variants
Actions
Navigation
Tools

Trial Key