As a result of building a website for a Torchbox client, I came up with a Drupal 5.x module to query the Postcode Anywhere and MailBuild webservices (if they look like an unlikely mix, don’t worry: they’re not coupled together generally, so you can use one without the other). I’ve been meaning to make it live for ages, but never got round to scrubbing the client’s data out of it. Now that we’ve unearthed the module for other work then I’ve finally finished cleaning it.
First, a bit of background. Postcode Anywhere provides a per-lookup paid webservice, converting UK postcodes into valid house names/numbers, streets, towns etc. It allows you to accept a user’s submission of a postcode to e.g. a signup form, then present them with a list of sample addresses, rather than them having to fill in all of their address details.
There’s only really one method exposed for the PA functionality, and it takes a text postcode and returns an array of results:
$data = pamb_pa_get_bypostcode($postcode);
MailBuild and CreateSend, on the other hand, provide a way to store email lists and send newsletter campaigns to subscribers. However, our client also wanted to use it to store snail-mail addresses, so they could use it for both requests for printed matter and also to keep subscribers up to date via email. It was possible to implement this using custom fields, of which the service permits around a dozen: address line 1, address line 2 etc.
There’s an existing Mailbuild module, which technically does the trick, but it’s overkill compared to what the client wanted. pamb’s integration is essentially just “push”: it passes the results of a form submission to CreateSend, by using a template (the one you’ve moved to your theme directory) to “theme” the data as an XML packet. If there are no problems then the system returns nothing; otherwise, it returns a structure of data including the HTTP response and the SOAP packet from the request.
Here’s some sample code:
/* Send SOAP packet */
$no_probs = pamb_mb_send_soap($form_id, $form_values);
/* If OK, set a generic message and redirect: the redirect will pick up
on the generic message and know all has gone well */
/* If not OK, $no_probs contains the diagnostics */
/* do something else */
- Download pamb: currently only available in subversion, but clients exist for Linux, Windows and OSX.
- Unpack it into your
- Edit the defines at the top of the file for your own Postcode Anywhere or MailBuild/CreateSend accounts.
- Stick the
pamb_soap.tpl.phpin your theme directory
- Switch on the module in the admin interface
You’re now ready to start developing with its handful of functions. Feedback more than welcome, as given Drupal’s minimal support for mailing-list functionality in core it’d be good to make this into a fully-functional module for similar third-party contact services, and even port it to 6.x.
[edit 2008-06-17: now hosted on Sourceforge]