[SUCS Devel] [Git][sucssite/sucs-site][beta] 4 commits: Fixed postcode lookup.
Imran Hussain
imranh at sucs.org
Sun Sep 27 18:05:48 BST 2015
Imran Hussain pushed to branch beta at sucssite / sucs-site
Commits:
584ed85c by Imran Hussain at 2015-09-27T17:15:00Z
Fixed postcode lookup.
Made the sucs site use the SUCS PAF lookup.
- - - - -
d1734db3 by Imran Hussain at 2015-09-27T17:20:58Z
Remove dev things.
- - - - -
d13114c4 by Imran Hussain at 2015-09-27T17:50:42Z
Merge branch 'master' into 'master'
Fixed postcode lookup
Made the sucs site use the SUCS PAF lookup.
See merge request !18
- - - - -
aac2527b by Imran Hussain at 2015-09-27T18:05:44Z
Merge branch 'master' into 'beta'
Push postcode lookup fix to beta
The title.
See merge request !19
- - - - -
3 changed files:
- components/signupajax.php
- htdocs/js/signup.js
- lib/validationData.php
Changes:
=====================================
components/signupajax.php
=====================================
--- a/components/signupajax.php
+++ b/components/signupajax.php
@@ -15,8 +15,7 @@ if (isset($_GET['key'])){
}
break;
case "postcode":
- $postcode=implode("", explode(" ", $_GET['value']));
- echo json_encode(lookup_postcode($postcode));
+ echo lookup_postcode($_GET['value']);
break;
case "username":
$username = $_GET['value'];
=====================================
htdocs/js/signup.js
=====================================
--- a/htdocs/js/signup.js
+++ b/htdocs/js/signup.js
@@ -21,21 +21,34 @@ function validate(){
}
function processPostcode(){
// lookup postcode
- $.getJSON("/signup/ajax",{key: "postcode",value: $('input#postcode').val().replace(/ /g,'')}, function(j){
+ $.getJSON("signup/ajax",{key: "postcode",value: $('input#postcode').val()}, function(j){
//populate dropdown
var options = '';
- if (j.length > 1) {
+ if (j.addresses.length > 1) {
// make dropdown visible
$('div#addseldiv').removeAttr("style");
- for (var i = 0; i < j.length; i++) {
- options += '<option>' + j[i] + '</option>';
+ for (var i = 0; i < (j.addresses.length); i++) {
+ options += '<option>';
+ if (j.addresses[i].flat != null) {
+ options += j.addresses[i].flat + "\n";
+ }
+ if (j.addresses[i].house != null) {
+ options += j.addresses[i].house + "\n";
+ }
+ if (j.addresses[i].road != null) {
+ options += j.addresses[i].road + "\n";
+ }
+ if (j.addresses[i].city != null) {
+ options += j.addresses[i].city + "\n";
+ }
+ options += '</option>';
}
$("select#addsel").html(options);
$('select#addsel option:first').attr('selected', 'selected');
}
- if (j.length == 1) {
+ if (j.addresses.length == 1) {
$('div#addseldiv').attr("style","display:none");
- $("textarea#address").val(j[0].replace(/, /g,'\n'))
+ $("textarea#address")
$('div#addressmessage').attr("style","color:green; float:right; clear:right;");
$('div#addressmessage').html("OK");
validation["address"]=true;
=====================================
lib/validationData.php
=====================================
--- a/lib/validationData.php
+++ b/lib/validationData.php
@@ -12,29 +12,15 @@ function lookupSID($sid) {
}
// lookup addresses from postcodes useing the univeritys website
-function lookup_postcode($postcode = "")
-{
- $url = "https://intranet.swan.ac.uk/common/postcodeLookup.asp?pCode=".$postcode;
- $referer = "https://intranet.swan.ac.uk/common/postcodeaddresslookup.asp";
+function lookup_postcode($postcode) {
+
+ include_once "../paf-key.php";
+
+ $url = "http://paf.sucs.org/?apikey=$apikey&postcode=".rawurlencode($postcode);
$req = curl_init($url);
- curl_setopt($req, CURLOPT_HEADER, false);
- curl_setopt($req, CURLOPT_REFERER, $referer);
- curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($req, CURLOPT_SSLVERSION, 3);
$page = curl_exec($req);
curl_close($req);
- $scrape = explode("returnAddress(\"", $page);
-
- $addresses = array();
- for ($i = 1; $i < count($scrape); $i++) {
- if (preg_match("/^[^,\"].+?\"/", $scrape[$i], $address)) {
- $addr = str_replace("<BR>\"", "", $address[0]);
- array_push($addresses, str_replace("<BR>", ", ", $addr));
- }
- }
- return $addresses;
}
?>
View it on GitLab: https://projects.sucs.org/sucssite/sucs-site/compare/af3d9f58620ad5bb42167fc154a6bb28cf72c78b...aac2527b71a1f0da1e26458a097a6d4781f5e9c3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/devel/attachments/20150927/b73e5a74/attachment-0001.html>
More information about the Devel
mailing list