AutoPostcode
Gravity Forms · developer guide

How to add postcode lookup to Gravity Forms

Learn how to add postcode lookup to Gravity Forms. Get a free API key.

No card required · Royal Mail PAF-verified data

Trusted UK address intelligence

PAF
UK address data
HTTPS
API requests
6
common questions
PAF-verified address lookup
Fast REST API & no-code plugins
GDPR-friendly, UK-hosted

To add postcode lookup to Gravity Forms, attach a lookup interface to your form and send requests through a protected server endpoint. Map the selected AutoPostcode result to your specific Gravity Forms address fields.

What do you need before you start?

Create an AutoPostcode account and a website API key, then check the pricing and API quickstart. Keep your key on a server you control and do not commit it to source control.

1. Prepare your form

Identify your form ID and inspect the actual address field input IDs. Keep the address field editable so visitors can enter details manually.

2. Test the upstream lookup

Set AUTOPOSTCODE_API_KEY in a server shell and run this request. The endpoint returns an array on success; it returns 404 when no addresses match.

curl --get "https://autopostcode.com/api/public/lookup" \
  --data-urlencode "postcode=SW1A 1AA" \
  -H "x-api-key: $AUTOPOSTCODE_API_KEY"

3. Initialise the form integration

Gravity Forms 2.9 and later emits gform/post_render. The following is an event hook, not a complete lookup UI: add the request, accessible results selector and field mapping for your form.

// Gravity Forms 2.9+: initialise after each form render.
document.addEventListener('gform/post_render', (event) => {
  if (event.detail.formId !== 1) return; // replace with your form ID
  const form = document.getElementById('gform_1');
  if (!form) return;
  // Attach your lookup UI here, guarding against duplicate listeners.
  // Call your own protected, rate-limited server endpoint, not the API key.
});

4. Protect and test your endpoint

Create a same-origin server endpoint with validation and rate limiting, keep the key server-side, and test AJAX rerenders, multipage forms and validation errors.

What should you check before switching over?

Replace the example form ID and implement the missing UI and endpoint before use. Avoid duplicate event listeners on rerender.

Use the API documentation and REST API reference for response fields and errors. Explore the postcode lookup API and address autocomplete API for the right search experience.

Platform reference: Gravity Forms: gform/post_render.

Get a free API key

Frequently asked questions

Does this require an AutoPostcode API key?

Yes. Create a website key in the AutoPostcode dashboard and keep it on your server.

Which Gravity Forms event should I use?

Gravity Forms 2.9 and later documents gform/post_render for initialising scripts after a form renders.

What happens when no address is found?

The postcode lookup endpoint returns 404 when it finds no addresses. Show a clear message and allow manual entry.

Should the key be included in browser JavaScript?

No. Keep the key on your server and protect any endpoint that makes requests on the visitor’s behalf.

Will the example work with any form ID?

No. Replace the example form ID and map the actual address field inputs in your own form.

How should errors be handled?

Handle invalid input, authentication failures, insufficient credit, no matches and timeouts; provide a manual-entry fallback.

Price beat guarantee

We'll beat any like-for-like UK address lookup price

Send us your current quote or invoice and we'll come back the same working day with a better price — plus free migration and integration support.

  • Beat any like-for-like UK quote, monthly or annual
  • Free migration + hands-on integration support
  • No setup fees, no lock-in, cancel any time

Ready to get started?

Add Royal Mail PAF-verified UK address lookup to your site in minutes — start free, no card required.