All Collections
Form Builder
Form Scripting & Calculations
Accessing data from an Address Field using Lua
Accessing data from an Address Field using Lua

How to pull out city, state or zip code information from an Address Field using our scripting language

Angela Lim avatar
Written by Angela Lim
Updated over a week ago

If you need to pull out individual elements from an Address Field, such as zip code or state, you can do so using our scripting language Lua.

To access this information, make sure the Address field in your form has a slug. 

You will want to store the information you need in a separate field, so make sure to add a Text field and also give it a slug. 

To access the data in the Address field, you will use the following naming patterns when writing your script (where address  is the name of the slug you've assigned to your Address field):

  • Street Address - answers.address.street 

  • Street Address 2 - answers.address.street_2 

  • Zip Code - answers.address.postal_code 

  • City - answers.address.city 

  • State - answers.address.state 

To write your script, simply assign the slug of the text field to the address info that you need above:

answers.home_state = answers.address.state 

Click Save Changes.

When a new form result is created, and the Address field is filled out, the State text field will automatically populate with the state!

Did this answer your question?