🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!
Guides & Tutorials October 20, 2026

Gravity Forms Brazil Address Form: CEP Autofill, CPF and CNPJ Validation

GravityExtra
Gravity Forms Brazil Address Form: CEP Autofill, CPF and CNPJ Validation

Anyone who has bought something online in Brazil knows the moment: you type your CEP, and the street, the neighbourhood, the city and the state appear before you finish blinking. Brazilians expect it. A form that asks for six separate things (in an order borrowed from another country, with a list of 195 countries) feels foreign, loses people on a phone keyboard, and fills your database with misspelt city names. This article shows what a good Brazilian address form does, and how the GravityExtra Brazil CEP Autofill add-on does it in Gravity Forms.

A Gravity Forms order form with the Brazil address type: the CEP 01310-200 was typed, and Logradouro, Bairro, Cidade and UF were filled in with Avenida Paulista, Bela Vista, São Paulo and SP, with a green message under the CEP and the cursor waiting in the Número field
Type the CEP and the address fills itself in. The cursor waits in Número, and every field can still be edited.

What is a CEP, and why does it do the work?

The CEP (Código de Endereçamento Postal) is the Brazilian postal code. It has eight digits, written 00000-000, and for most streets in the country it identifies the street itself, not a whole area. A single CEP therefore tells you the logradouro, the bairro, the cidade and the UF. For a small town with a single CEP it gives the city and the state only, and the visitor still types the street.

That makes the CEP the best first question of an address form. Ask it first, look it up, and fill in the rest. The visitor types eight digits plus a número, and the form is done.

The right order, in the right language

Gravity Forms has address types for the world, the United States and Canada. A Brazilian address is different in three ways. The order starts with the CEP. The street number (número) and the neighbourhood (bairro) are separate pieces of data that Brazilian systems expect. And the state is a UF, a two-letter code from a list of 27 units, 26 states and the Federal District.

With the add-on, the Address Type list of the Address field has a new entry, Brazil (CEP). The field shows the CEP, the logradouro, the número, the complemento, the bairro, the cidade and the UF, with Portuguese labels, a numeric keyboard on phones for the CEP and a list of the 27 UFs. The country is Brasil and is saved without being shown.

What happens when the visitor types the CEP

The CEP is formatted as 00000-000 while the visitor types. On the eighth digit the form asks for the address, and a short message tells the visitor that it is working. A moment later the logradouro, the bairro, the cidade and the UF are filled in, and the cursor moves to Número, because that is the only thing left to type. If the CEP has no street, the cursor moves to Logradouro instead.

Nothing is locked. A visitor who knows that the street on their door is spelt differently can change the text, and a visitor who types another CEP gets the new address. The lookup never runs when the form is sent, so it can never be the reason a form fails.

Where the data comes from, and why your server asks

Two free services answer CEP questions without an account or a key. ViaCEP, at viacep.com.br, answers a request with the logradouro, bairro, localidade and uf of a CEP, and says erro when it does not know it. BrasilAPI, at brasilapi.com.br, is an open source project that asks several sources and answers with the street, neighbourhood, city and state.

The add-on uses ViaCEP first and BrasilAPI when ViaCEP is down, too slow, or does not know the CEP. You can reverse the order or use only one. And it does not let the visitor’s browser talk to either service. The browser asks a small REST route of your own WordPress site, and your server asks the service. This has four good effects.

  • The service sees your server, not every visitor. Nothing but the eight digits of the CEP is sent.
  • A cache keeps each answer for 30 days (you choose), so a popular CEP is one request, not thousands. The services ask for moderate use, and the cache is how you give it.
  • A nonce and a rate limit per visitor stop a script from using your site as a free CEP service.
  • Your page does not depend on a third-party script, and a service that is down does not break it: your server skips it for a minute and tries the other one.

If both services are down, the visitor sees one clear sentence and types the address. The form is sent as usual.

The messages that matter

Three situations need words, and the add-on has them in Portuguese. When the CEP does not exist: CEP não encontrado. Confira o número ou preencha o endereço manualmente. When the services cannot answer: Não foi possível consultar o CEP agora. Preencha o endereço manualmente. When the CEP has fewer than eight digits: Informe um CEP com 8 números. Each message tells the visitor what to do next. You can change any of them with a filter.

CPF and CNPJ, because Brazilian forms ask for them

A Brazilian form often asks for a CPF (a person’s tax number) or a CNPJ (a company’s). Both end with two check digits calculated from the others, so most typing mistakes can be caught on the spot. The add-on adds an option to Single Line Text fields: choose CPF or CNPJ, and the field adds the usual dots, slash and hyphen while the visitor types, then checks the length and the check digits when the form is sent.

The CNPJ is changing. From 2026 the Receita Federal issues CNPJs with letters and digits in the first twelve positions, and the same two numeric check digits. The validator accepts both the numeric and the alphanumeric kind. A word of caution that we repeat in the settings: a valid check digit says that a number is well formed, not that it is registered or belongs to the person who typed it. Use it to catch typos, not to prove identity.

An address that reads like an address

Once the form is sent, the address should look right in the places where people read it. On the entry page, in the all fields table of a notification and in the merge tag of the whole field, the add-on writes the address the Brazilian way: logradouro, número and complemento on the first line, the bairro on the second, the cidade and the UF on the third, then the CEP and Brasil. A modifier gives the same address on one line, which is handy for a label or a delivery system.

The Gravity Forms entry detail page in the WordPress admin showing the Brazilian address printed as Avenida Paulista, 1578 - Conjunto 12, Bela Vista, São Paulo - SP, CEP 01310-200 and Brasil
The entry prints the address the Brazilian way, and número and bairro are saved as separate inputs.

Each input is also saved on its own, so the CSV export has a column for the UF, one for the cidade and one for the CEP, and you can sort or filter your orders by state in a spreadsheet. The saved CEP always has the form 00000-000, whatever the visitor typed.

Works where real forms live

Real forms are not a single address on a single page. The add-on works in multi-page forms, where the visitor can go back and forward and keep the values. It works in AJAX forms, where the form is drawn again after a validation error and the lookup keeps working. And it works with several address fields in one form, such as a billing and a delivery address, each with its own lookup. If you want the Brazilian layout without the lookup for one field, there is a switch for that.

Setting it up in five minutes

  1. Install the add-on and activate your licence in Forms, Settings, Brazil CEP.
  2. Add an Address field to your form and choose Brazil (CEP) as the address type.
  3. Optionally choose the data source, the cache time and the rate limit in the settings.
  4. Add the CPF or CNPJ option to the text fields that need it.
  5. Open the form on your site, type a CEP you know, and check the entry and the notification.
The add-on settings in Forms, Settings, Brazil CEP: the licence box, the choice of data source between ViaCEP and BrasilAPI, how long answers are kept, the lookups per visitor and minute, and the mask and focus options
One settings page for the data source, the cache, the rate limit and the behaviour of the form.

What it does not do

It does not know a visitor’s número or complemento, so it does not fill them. It does not check that a street really has the number the visitor typed. It does not guarantee that the services know every new CEP, which is why the visitor can always type the address. It does not store anything about the lookup beyond the cached answer for the CEP. And it does not validate that a CPF or CNPJ is registered.

Frequently asked questions

Do I need an account with ViaCEP or BrasilAPI?

No. Both are free and need no key. Read their pages before you go live; the add-on keeps your usage low with a cache and a rate limit.

Does it slow my form down?

No script from a third party loads on your page. The lookup is one small request to your own site, and a cached answer comes back at once.

What happens if the services are offline on the day of my sale?

The visitor sees a short message and types the address. The form is sent as usual, and nothing is lost.

Does it work without a licence?

The Brazil address type keeps rendering and saving, so nothing breaks. The lookup, masks and validators wait for a valid licence.

A Brazilian customer should type a CEP and a número, and then be done. With the Brazil address type, the form does the rest, and your entries come out clean.

Let your Brazilian customers type a CEP instead of a whole address

See the Brazil CEP Autofill add-on

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr