Integrate NGP-VAN API into Wordpress website

osama112

New Member
I need to integrate the NGP API (www.ngpvan.com) into a Wordpress website. I am not that experienced with PHP, but if you explain what to do I should be able to figure it out. New Media Campaigns created a toolkit for the API, and this website details what I am attempting to achieve (http://www.moiagroup.com/archives/using-the-ngp-api/664). Essentially I want an email submission form that is themed with the style.css just like any form. But when a user submits the form, it should send the data straight into the NGP database. The link above describes how to do this but I am having trouble figuring out where to put the code. They offer two pieces of PHP code and it uses the NuSoap library. If you could point to where I should place these files so that I have a working form that would be fantastic. Thanks in advance. Client Code\[code\]<?phprequire_once('nusoap/nusoap.php');class NgpEmailSignupClient { public $credentialString; public $mainCode; public $campaignID; function NgpEmailSignupClient($credentialString, $mainCode, $campaignID) { $this->debug = false; $this->credentialString = $credentialString; $this->mainCode = $mainCode; $this->campaignID = $campaignID; } function addEmail($email, $zip, $firstName = '', $lastName = '') { if (!$zip) $errs[] = "Zip code is required."; if (!$email) $errs[] = "Email is required."; if ( count($errs) ) { echo '<h1>Error</h1><ul>'; foreach ($errs as $err) { echo '<li>'.$err.'</li>'; } echo '</ul>'; exit; } // Create the XML string containing all our data // http://www.myngp.com/ngpapi/transactions/Email/ContactWithEmailSet.xsd $xml = '<?xml version="1.0" encoding="utf-8"?>'; $xml .= "<contactWithEmailSet>"; $xml .= "<contact>"; $xml .= ( isset( $lastName ) && !empty( $lastName ) ) ? "<lastName>{$lastName}</lastName>" : '<lastName />'; $xml .= ( isset( $firstName ) && !empty( $firstName ) ) ? "<firstName>{$firstName}</firstName>" : '<firstName />'; $xml .= ( isset( $zip ) && !empty( $zip ) ) ? "<zip>{$zip}</zip>" : '<zip />'; $xml .= ( isset( $email ) && !empty( $email ) ) ? "<email>{$email}</email>" : '<email />'; $xml .= "</contact>"; $xml .= "<mainCode>{$this->mainCode}</mainCode>"; $xml .= "<optIn>1</optIn>"; $xml .= "<campaignID>{$this->campaignID}</campaignID>"; $xml .= "</contactWithEmailSet>"; $client = new nusoap_client('http://www.myngp.com/ngpapi/APIService.asmx?wsdl', true) or die("Error instantiating SOAP client"); // Do the call $params = array( 'RequestXML' => $xml, 'transType' => 'contactWithEmailSet', 'credentialString' => $this->credentialString ); $result = $client->call('processRequestWithCreds', $params); if ($client->fault) { //print_r($client->return); //echo $xml . "\n\n"; return $err; exit; } else { // Check for errors $err = $client->getError(); if ($err) { //print_r($client->return); //echo $xml . "\n\n"; //echo $err; return $err; exit; } else { return true; exit; } } }}\[/code\]And the Demonstration Code\[code\]<?phpinclude_once('NgpEmailSignupClient.php');// Each of these three values needs to be customized for your specific application.$credentialString = "6PPfar0e/MFaVhEiYhfgsf%44fsfie5i8JKHGKJhfasdhgj675We";$mainCode = "WebEMAIL";$campaignID = 1234;// These values will presumably come from script or form input// They should be validated before reaching this point$email = '[email protected]';$zip = '12345';$ngpClient = new NgpEmailSignupClient($credentialString, $mainCode, $campaignID);if (true === $ngpClient->addEmail($email, $zip)) { echo "Success!";} else { echo "Failure!";}?>\[/code\]
 
Back
Top