Hi Bob, i saw this and a few other related posts that have commented on reliable postal addresses so thought i’d share my experience here. First ever post so looking to give something back as i have benefited a lot from reading other posts and solutions (including Velo Ninja’s), getting on youtube etc. I’m certainly no Velo Ninja but hope it helps. This response is in a UK context.
The standard Wix address lookup is where i started just like you. I was looking to capture additional member info and i found similar issues that it didn’t always correctly send this to Contacts so often the postal address would be incorrect. A free text address input has too much user friction and keying error risk so i wanted something like the auto look up but with greater reliability
For the UK the best way imo to get accurate postal addresses is using a licensed Royal Mail PAF provider. There are lots of providers and it’s personal choice but i found Ideal Postcodes the easiest to set up for me at the time of posting this. I used a Postcode look up which i explain below and show some code, this is partly because an address autocomplete looked beyond my skillset.
Here’s the set up and code, I hope it helps:
STEP 0: Wix site set up with developer mode enabled and a members area set up
STEP 1: Set up a trial account and get an API key from Ideal PostCodes. UK Address Verification - Ideal Postcodes (ideal-postcodes.co.uk)
STEP 2: Page Elements
Attached to a website Form where you want to capture the postal address info include each of:
- A short answer basic input field [#input18 in the front end code below]
· This form field should not be saved to any submission data. Prompt text something like “add your postcode here”
2. A button [#button21 in the front end code below]. Label “Find address” or similar
- A drop down selector [#dropdown5 in the front end code below]
· This form field should be saved to Address submission in the members area. All default choices should be cleared from the dropdown box element in the page editor so that there are no available choices
STEP 3: Backend code (new jsw file called P_Postcode.jsw)
import { fetch } from ‘wix-fetch’ ;
export async function FindPostCode ( postcode ) {
let baseUrl = “https://api.ideal-postcodes.co.uk/v1/postcodes/”
let url = baseUrl + postcode
const headers = { “Authorization” : ‘api_key=“yourkeyvalue”’ } //you could/should use API secrets manager but this particular site provider has some additional features which I understand make this ok
const response = await fetch ( url ,
{ method : “get” ,
headers : headers ,
})
const AddressResults = await response . json ()
const AddressResultsData = AddressResults . result
return AddressResultsData
STEP 4: Front end code
import { FindPostCode } from ‘backend/P_Postcode’ ;
export async function button21_click ( event ) {
let list = await FindPostCode ()
let n = list . length
for ( let i = 0 ; i < n - 1 ; i ++) {
let label = list [ i ]. line_1 + " , " + list [ i ]. postcode
let value = list [ i ]. line_1 + " , " + list [ i ]. line_2 + " , " + list [ i ]. line_3 + " , " + list [ i ]. post_town + " , " + list [ i ]. postcode
let opts = $w ( "#dropdown5" ). options ;
opts . push ({ “label” : ${ value }
, “value” : ${ value }
});
$w ( “#dropdown5” ). options = opts ;}
}