Commit 985c3c3f authored by mattwire's avatar mattwire
Browse files

Some providers require space in postcode, some don't

parent 195a02e4
......@@ -41,7 +41,7 @@ class CRM_Civicrmpostcodelookup_Page_Afd extends CRM_Civicrmpostcodelookup_Page_
* Function to get address list based on a Post code
*/
public static function search() {
$postcode = self::getPostcode();
$postcode = self::getPostcode(TRUE); // FIXME: Check whether API requires space or not
$number = CRM_Utils_Request::retrieve('number', 'String', $this, false);
$querystring = self::getAFDCredentials(1);
......
......@@ -40,7 +40,7 @@ class CRM_Civicrmpostcodelookup_Page_Civipostcode extends CRM_Civicrmpostcodeloo
* Function to get address list based on a Post code
*/
public static function search() {
$postcode = self::getPostcode();
$postcode = self::getPostcode(TRUE);
$number = CRM_Utils_Request::retrieve('number', 'String', $this, false);
$querystring = self::getCivipostcodeCredentials(1);
......
......@@ -43,7 +43,7 @@ class CRM_PostcodeLookup_Page_Ajax extends CRM_Civicrmpostcodelookup_Page_Postco
}
public static function search() {
$postcode = self::getPostcode();
$postcode = self::getPostcode(TRUE); // FIXME: Check whether API requires space or not
$number = CRM_Utils_Request::retrieve('number', 'String', $this, true);
$qaCapture = self::getQACapture();
......
<?php
require_once 'CRM/Core/Page.php';
abstract class CRM_Civicrmpostcodelookup_Page_Postcode extends CRM_Core_Page {
/**
* Get the postcode from the submitted values, with or without space.
* @param bool $space
*
* @return string
*/
protected static function getPostcode($space = FALSE) {
$postcode = CRM_Utils_Request::retrieve('term', 'String', $this, true);
return self::format($postcode, $space);
}
/**
* Format a UK postcode so it has a space before the last digit, or doesn't if $space is FALSE
* @param $postcode
* @param bool $space
*
* @return string
*/
protected static function format($postcode, $space) {
// Strip non-alpha characters
$postcode = preg_replace('/\W/', '', $postcode);
if (strlen($postcode) > 4) {
($space) ? $spacerChar = ' ' : $spacerChar = '';
return preg_replace('/^(.*)(\d)(.*)/', "$1{$spacerChar}$2$3", $postcode);
}
return $postcode;
}
}
......@@ -41,6 +41,7 @@ class CRM_Civicrmpostcodelookup_Page_PostcodeAnywhere extends CRM_Civicrmpostcod
* Function to get address list based on a Post code
*/
public static function search() {
// PostcodeAnywhere API works with postcodes when they have a space and when they don't.
$postcode = self::getPostcode();
$querystring = self::getPostcodeAnywhereCredentials(1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment