Jump to content

UK Autofill Address from Postcode


magga

Recommended Posts

Hi everyone,

 

I have recently implemented an autofill address from postcode script into my site so I'd like to share this for other UK users to take advantage of!

 

You can see a demo here, however please note that it is in demo mode only at the moment so only the postcode ZZ99 or a Nottingham postcode e.g. NG1 1GA will work:

 

https://www.magdesign.co.uk/clients/register.php

 

You can also see it on the cart page:

 

https://www.magdesign.co.uk/clients/cart.php?a=checkout

 

You do have to buy credits to use the address autofill as the lookups are done from a big database of addresses held elsewhere. As I can't place adverts for other sites on here, if anyone wants a 10% promotional discount code for their first order of postcode credits and details of where to purchase them from, please PM me.

 

I have attached 3 files that are needed for this lookup to work, you can upload these to anwhere you like, just make sure they are all in the same folder and you put the correct path to them in the template files.

 

Firstly, you need to edit your header.tpl file:

 

Add this line within your <head></head> tags:

 

<script type="text/javascript" src="/SPL_AJAX_Full.js"></script>

 

The path above must reference where the SPL_AJAX_Full.js script is.

 

Next edit your clientregister.tpl file:

 

Find the line:

 

<tr><td class="fieldarea">{$LANG.clientarealastname}</td><td><input type="text" name="lastname" size=30 value="{$clientlastname}"> *</td></tr>

 

And move the table row that includes the postcode field to be below it, and add an id="postcode" to the text input:

 

<tr><td class="fieldarea">{$LANG.clientarealastname}</td><td><input type="text" name="lastname" size=30 value="{$clientlastname}"> *</td></tr>
<tr><td class="fieldarea">{$LANG.clientareapostcode}</td><td><input type="text" name="postcode" [b]id="postcode"[/b] size=10 value="{$clientpostcode}"> *</td></tr>

 

Next, you must add a button next to this field that will call the address lookup script:

 

<tr><td class="fieldarea">{$LANG.clientareapostcode}</td><td><input type="text" name="postcode" id="postcode"size=10 value="{$clientpostcode}"> * [b]<input type="button" onclick="Javascript:SPLGetAddressData(document.getElementById('postcode').value); javascript: document.getElementById('addresslist').style.display='';" value="Find Address">[/b]</td></tr>

 

Next you should add a table row below the postcode row, this will be where the addresses are then listed, the style="display: none" makes it only appear when the lookup button is clicked:

 

<tr id="addresslist" style="display: none"><td class="fieldarea"></td><td><div id="SPLSearchArea" /></div></td></tr>

 

Make sure the field id's referenced in the script are the same as the ones in your template. Towards the bottom of the SPL_AJAX_Full.js file, you will see a load of fields:

document.getElementById("company").value=COMP;
document.getElementById("postcode").value=POSTCODE;
document.getElementById("line1").value=LINE1;
document.getElementById("line2").value=LINE2;
document.getElementById("town").value=TOWN;
document.getElementById("county").value=COUNTY;
document.getElementById("country").value=COUNTRY

The bracketed values refer to id of the field (in your template) where you want that particular part of the address to be inserted. If you used the above values, then your Company text field in your template MUST have an id of "company", your Address 1 must have an id of "line1" and so on, much like below:

 

<input type="text" name="companyname" [b]id="company"[/b] size=30 value="{$clientcompanyname}">
<input type="text" name="address1" [b]id="line1"[/b] size=40 value="{$clientaddress1}">

 

You then need to add the CSS into your stylesheet:

 

<STYLE type="text/css">
.SPLAddressListSt{
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  margin-top: 0;
  margin-bottom: 0;
  width: 80mm;}
.SPLAddressListStBottomLine{
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10px;
  text-align: center;
  margin-top: 0;
  margin-bottom: 0;
}
.SPLAddressListStErrorLine{
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  text-align: center;
  margin-top: 0;
  margin-bottom: 0;
}
.SPLAddressListLicenseLine{
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10px;
  text-align: center
  margin-top: 0;
  margin-bottom: 0;
}
</STYLE>

 

SPLAddressListSt is the style of the address selection box

SPLAddressListStBottomLine is the style of the line below selection box

SPLAddressListStErrorLine is the style of text which appears if Postcode is not found

SPLAddressListLicenseLine is the style for the License information

 

When you sign up for the credits, you will be given a "Data Key" which you must enter at the top of the 2 attached .php files.

 

You can use all this code in the exact same way on your viewcart.tpl page too as clients can also register on this page.

 

Hope this is useful for you all, any questions, please ask me!

AJAX PHP Full Address.zip

Edited by magga
Link to comment
Share on other sites

Looks like a great idea but when I tried your register page it didn't find my or other postcodes I entered which I know are valid.

 

In addition, if it doesn't find the postcode first time and you change the value to check, the submit button doesn't appear to checking the new value. You have to refresh the page to get the script firing again.

 

Looks like a great add-on though if you can iron out these issues and I would definitely be interested :)

Link to comment
Share on other sites

Yes I'm aware of Postcode Anywhere, seems like it's harder to integrate however and also the credits are slighty more expensive on your first order, £250 for 6,000 with them or £210 (+ 10% off your first order with promo code) for 5,000 with Simply Postcode.

 

This thread is aimed at UK users initially, hence why it's stated in the title.

Link to comment
Share on other sites

Yes I'm aware of Postcode Anywhere, seems like it's harder to integrate however and also the credits are slighty more expensive on your first order, £250 for 6,000 with them or £210 (+ 10% off your first order with promo code) for 5,000 with Simply Postcode.

 

I disagree about intergration -it's an absolute doddle! One line of code next to the post code field on your form - then the software does the rest.

 

All credits are time limited so buying 5000 if you're not going to use them is surely false economy (unless you're really doing 30 lookups a day!) We pay about £100 a year for the credits we need.

 

(plus neither of the examples you give above work for me!)

Link to comment
Share on other sites

You should post an integration on here yourself in that case for Postcode Anywhere, I'm just sharing this with others. You don't have to use it if you don't like it!

 

I used 5,000 as an example, they last for 1 year in any case.

 

If you read the original post you will see it says "please note that it is in demo mode only at the moment so only the postcode ZZ99 or a Nottingham postcode e.g. NG1 1GA will work".

Link to comment
Share on other sites

We use http://www.postcodeanywhere.co.uk - a much better system from what I can see.

 

One simple line of code needed and provides worldwide postcodes as well as UK.

 

Not sure how it compares on price.

 

Do you actually use this along with WHMCS?

 

From what I can see in the documentation it is not one simple line of code and looks like it would be fairly complicated to integrate with the full International postcode service.

 

If you have got this working, would you care to share the link so I can take a look.

 

Cheers

Link to comment
Share on other sites

We tested this last night (postcodesanywhere).

 

One line of code and it works perfectly. You set everything up from their web interface, it pulls all the form fields and lets you select what goes where.

 

Took 5 minutes to setup the test.

 

Very impressive though.

Edited by XN-Matt
Link to comment
Share on other sites

Do you actually use this along with WHMCS?

 

From what I can see in the documentation it is not one simple line of code and looks like it would be fairly complicated to integrate with the full International postcode service.

 

If you have got this working, would you care to share the link so I can take a look.

 

Cheers

 

Yep - works a treat with a number of websites we run. I'll PM you a link (to avoid abuse)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated