For the uninitiated, NGP Software is an excellent online tool for campaigns to help them raise money and manage constituents. They have an excellent set of APIs for submitting contributions, newsletter sign-ups and volunteer information. The problem is their APIs are mostly targeted toward Windows/ASP development. For what it’s worth, they do include an example using JavaScript.
The NGP folks have created a plugin for Drupal that integrates directly into the CMS. I tried installing it on a clean Drupal install and it didn’t work, giving SOAP errors.
Rather than reverse engineering the Drupal plugin I stripped out the basic pieces and put them together to work within the Zend Framework.
We don’t even use SOAP for this call, simply the Zend_Http_Client class.
The following are assumed:
1. You have received a valid form (using Zend_Form, of course).
2. Are a client of NGP or have a client login.
3. The CWP is set up on the site and you have generated your Credentials string.
4. You are using Zend Framework 1.7 or higher.
5. The $data[] array are reflections of the Zend_Form elements.
This would be the “process code.” Be sure to run a “convert to ASCII” code on the code block below, since WordPress like curlify-ing quotes.
$data = $this->_request->getPost();
$xml ='<VolunteerSignUp>';
$xml.='<ContactInfo>';
$xml.='<LastName>'.trim(urlencode($data['lastname'])).'</LastName>';
$xml.='<FirstName>'.trim(urlencode($data['firstname'])).'</FirstName>';
$xml.='<Address1>'.trim(urlencode($data['address1'])).'</Address1>';
$xml.='<Address2>'.trim(urlencode($data['address2'])).'</Address2>';
$xml.='<City>'.trim(urlencode($data['city'])).'</City>';
$xml.='<State>'.trim(urlencode($data['state'])).'</State>';
$xml.='<Zip>'.trim(urlencode($data['zip'])).'</Zip>';
$xml.='<Email>'.trim(urlencode($data['email'])).'</Email>';
$xml.='<HomePhone>'.trim(urlencode($data['phone'])).'</HomePhone>';
$xml.='</ContactInfo>';
$xml.='</VolunteerSignUp>';
$post='Credentials={YOUR_AS-IS_CWP_CREDENTIALS_STRING}&data='.$xml;
$client = new Zend_Http_Client("https://services.myngp.com/ngponlineservices/VolunteerSignUpService.asmx/VolunteerSignUp");
$response = $client->setRawData($post, 'application/x-www-form-urlencoded')->request('POST');
A bit later I will be posting the Zend Framework code used for the contribution and newsletter sign ups.