Talk:Postal Address Verification

From CDYNE Wiki
Jump to navigation Jump to 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

  1. INTITAL VARIABLE
  2. INSERT LICENSE KEY BELOW

$license_key = "put license key here";

  1. 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'];


  1. 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 . "
"; echo $xmlDeliveryAddress . "
"; echo $xmlCity . "
"; echo $xmlStateAbbrev . "
"; echo $xmlZipCode . "
";

// #################################### // # PRESENT TO CLIENT // ####################################

 if ($xmlAddressError == "false") {
    echo "ADDRESS IS CORRECT:" . "
"; echo $address . "
"; echo $city . "
"; echo $state . "
"; echo $zip . "
"; } else { echo "ADDRESS NOT FOUND:" . "
"; echo $address . "
"; echo $city . "
"; echo $state . "
"; echo $zip . "
"; }



?>