Address lookup via a web service


Hi, I’m looking to create an address lookup on our site to return household data.

I’ve so far been able to do an address lookup in a custom form asset, which would return html from the web service and display it in a dropdown list, but have been unable to do anything with the selected values.

For example:
A user enters their post code and hits search,
This then goes away to a web service and returns all properties in that post code into a dropdown list,
The user can then select their address from the dropdown list,
This would select the value (uprn) from the selected index and call another web service,
The other web service would return the required result.

Any help/tips would be great.


(Petri Iivonen) #2

I built mine with an intermediate PHP handler that connects to the database and returns a JSON string.

  1. Send AJAX request to the handler script (I’m using jQuery)
  2. Handler validates the request and
  3. connects to the database and
  4. returns results in JSON
  5. Requesting script fetches the JSON and updates form fields accordingly or
  6. sends another query for narrower resutls and
  7. of course handles all exceptions etc.

Alternatively, you can use database source asset (DB Data Source) and asset listings of what ever you fancy to achieve the same. That wouldn’t be portable or shareable though.


Hi Petri,

Thanks for the reply, creating our own PHP handlers is what we’ve wanted to look at for a while now.
Is there a Squiz manual that explains how we would achieve this? (Creating the actual PHP files, where these would sit and how we would call it)

What would be great is if we could create our own asset types and be able to re-use them. (Like the asset listing/Google Map assets)

We’ve not really looked at the db data source asset as we’re unsure as to how secure this is, although we would handle any SQL injections in our stored procedures.

Thanks again for the advice, very useful!


(Tbaatar) #4

From what you are trying to achieve it should just be possible with Vanilla JS or with a chain of Matrix REST JS or combination of the both.

The key is the response header/body message for errors. If its unique then you can easily print out the returns in IF/ELSE statement with Rest JS.

(Petri Iivonen) #5

My solution is completely independent from Matrix because I wanted to build something that all our services can utilise. If you are thinking of creating your own asset type, there used to be demo assets in older versions. Unfortunately Squiz stopped encouraging the community from creating anything years ago, guess they are scared to death that Matrix would become truly open source if they did. So they removed them in their drive to make Matrix more open in line with its open source credentials (yeah, that’s sarcasm).

One way you can start learning how to create your own assets is take one type, e.g. standard page, and see how it works and then build from that. I wouldn’t bother though if you still depend on (paid for) Squiz support.

By the way, external DB connections and data source asset type are properly secured so you shouldn’t worry about that.