Address lookup from postcode using external service

jamestamr - May 19, 2008 - 13:42

A site I am building want to introduce a postcode lookup service using Postcode Anywhere which works by displaying the post code field above all the other address fields (address1, address2, town, county, country) which gets button next to it which runs a piece of javascript held on the postcode anywhere servers.

This then brings up either a popup window with a list of possible addresses or an inline list of addresses which is an option, when you configure the software.

I am not sure of how you would implement this at all. I have been reading through Drupal Pro Development book which is very good and covers modules pretty well, but only in a basic sense. I am not sure how the rest of the site is going to pan out yet, so I am unsure of whether it would be best to make this module standalone, part of cck or part of the profile.

This will have to be available to anonymous users so I think keeping it out of the profile is the best bet for our integration but I am unsure of how to move that data in to the profile for users who are registered when they first use a form with the address capture, so maybe it has to be made for both? Thus a standalone module with 2 seperate modules to integrate with CCK and profile.

I have no idea of how to accomplish this but some pointers would be great, and I would of course make it available to the Drupal community as I am sure it would be of to use to others.

I am unsure of whether it

gpk - May 19, 2008 - 17:56

I am unsure of whether it would be best to make this module standalone, part of cck or part of the profile.

This will have to be available to anonymous users so I think keeping it out of the profile is the best bet for our integration but I am unsure of how to move that data in to the profile for users who are registered when they first use a form with the address capture

I think you have 2 separate questions here. The first is where to put the postcode field and store the postcode/address information; the second is how to implement it.

You could easily create a module that implements the Postcode Anywhere functionality using http://api.drupal.org/api/function/hook_form_alter/5 - it wouldn't necessarily have to care whether it was a profile field, a node field or whatever. It would just attach the relevant JS (and maybe add the address fields) the relevant forms. There are different ways of telling the module where to do its stuff - it could scan all forms (expensive) looking for a certain id; or you could have a settings page that let you specify which forms to interfere with.

Then a separate module could handle any questions of getting data from one place to another, should that prove necessary.

gpk
----
www.alexoria.co.uk

Had obviously by passed the

jamestamr - May 20, 2008 - 08:44

Had obviously by passed the hook_form_alter in the book as there appears to be only 1 small paragraph of text relating to it.

Thanks for your reply,

Action Medical Research - www.action.org.uk

>there appears to be only 1

gpk - May 20, 2008 - 09:02

>there appears to be only 1 small paragraph of text relating to it
And a passing reference at that. Not bad, for what is probably the most overused hook in Drupal (it basically lets you do anything ...)

gpk
----
www.alexoria.co.uk

Rather than starting a new

jamestamr - May 20, 2008 - 14:15

Rather than starting a new thread, as the question is about hook_alter_form() I have created another module to create a slideshow with the ability to add slides by creating a new custom node. What I want to do is set comments to disabled and show on front page to off. And I also want to remove the menu and path fieldsets, but fieldsets don't have the disabled attribute on them.

And I did find another reference to it, so there are 2 references, although only one of the references is in the Index.

EDIT: I have found that settings $form['menu'] = FALSE and $form['path'] = FALSE gets rid of the forms, is this a good way of doing it?

EDIT2: To remove the Promote to front page, I used $form['options']['promote']['#default_value'] = 0; I don't know if this is good practice though?

Action Medical Research - www.action.org.uk

>Rather than starting a new

gpk - May 20, 2008 - 19:15

>Rather than starting a new thread
Which would really have been the better option ;)

>EDIT: I have found that settings $form['menu'] = FALSE and $form['path'] = FALSE gets rid of the forms, is this a good way of doing it?
I'm guessing now really but those elements are I think added by menu.module and path.module, using hook_form_alter(). Maybe you can just unset them.

>EDIT2: To remove the Promote to front page, I used $form['options']['promote']['#default_value'] = 0; I don't know if this is good practice though?
Doesn't that leave the checkbox visible? You might need to change the #type to 'value'. Or leave it visible but set #disabled to TRUE.

gpk
----
www.alexoria.co.uk

Actually rather than

gpk - May 21, 2008 - 07:07

Perfect, thank you. Now to

jamestamr - May 21, 2008 - 08:53

Perfect, thank you. Now to spend another day trying to get this to work :)

Action Medical Research - www.action.org.uk

PA integration

jp.stacey - May 23, 2008 - 09:25

I've got a small module that takes a postcode, checks it with PA's service, and returns an array of matches. You have to hardwire the PA account details in the module for now, but otherwise it works:

http://www.jpstacey.info/blog/2008/05/22/postcode-anywhere-and-mailbuild...

It means you can not-worry about the PA service and just assume you're getting the data from "wherever". You can plug it into hook_form_alter() as suggested above (which is sort of what we did: we called it to populate the #options parameter of a form field of #type=>select as we were building our own form).

(Should be up on Sourceforge later today, as I've just got the project-approved email: is core Drupal still GPL2, as I'm picking my licences now?)

I checked ...

newdru - May 24, 2008 - 04:54

your site and the download is not available. is it possible to download and try it from somewhere?

thanks

Oh, flip and heck: should be

jp.stacey - May 27, 2008 - 20:38

Oh, flip and heck: should be fixed now. Sorry about that. Direct link: http://www.jpstacey.info/blog/files/code/pamb.tgz

Now on sourceforge

jp.stacey - June 17, 2008 - 19:05

This has now gone into Sourceforge: http://sourceforge.net/projects/drupal-pamb/

I'd be interested in putting a bit more work into developing it if anyone finds it of use. We've had successes in-house with it, but it would be good to work out how others might use it.

Any progress with pamb

kenorb - October 13, 2008 - 08:56

Any progress with pamb module?

Sounds very interesting,

jamestamr - May 27, 2008 - 08:20

Sounds very interesting, although the download link on the site doesn't work.

Action Medical Research - www.action.org.uk

The Web Service

PhilipMarlowe - September 16, 2008 - 15:28

You may be interested in Postcode Anywhere's latest launch, The Web Service ... mashups and code snippets galore.

Postcode Anywhere Module

kenorb - March 27, 2009 - 15:24
 
 

Drupal is a registered trademark of Dries Buytaert.