Select to view content in your preferred language

Restrict submission of form if geopoint is not within the city?

1596
6
Jump to solution
06-04-2020 02:27 AM
ŽeljkoPušec
Emerging Contributor

Hello,

first, I used pulldata on geopoint to extract full addres to field named "address". My idea is to create calculation which will check if the full address with street name and number etc., contains name of the city. If not, then return value of null, and as it is requiered field, it will forbid submission of the form if the geolocation is set outside of that city.

Well, I'm not sure this logic is right, but the calculation I wrote sure isn't:

if(${address}) regex(., 'Zlatar Bistrica'), 1, null)

Any help would be much appreciated, thank you.

0 Kudos
1 Solution

Accepted Solutions
DanteLee
Frequent Contributor

You could set the constraint column with contains:

contains(${address},'Zlatar Bistrica')‍

View solution in original post

6 Replies
DanteLee
Frequent Contributor

You could set the constraint column with contains:

contains(${address},'Zlatar Bistrica')‍
ŽeljkoPušec
Emerging Contributor

It works!

Thank you kindly for your reply!

0 Kudos
ŽeljkoPušec
Emerging Contributor

Hello, after I used pulldata on geopoint to extract full addres to field named "address", I used this calculation for a required question: "Is geopoint within Zlatar Bistrica city?":

if(contains(${address},'Zlatar Bistrica'), 'yes', null)

So, the result is that form can't be submitted if the geopoint is se ouside the city.

Now I'm working on a same form for a neighbour city called "Zlatar". But if I use analog calculation:

if(contains(${address},'Zlatar'), 'yes', null)

it is obvious that a geopoint can be set in city "Zlatar Bistrica", because contains "Zlatar" . It shoudn't be posible, so how can I write a calculation for an address that must contain "Zlatar" and nust NOT contain "Bistrica" at the same time? 

Thanks very much!

0 Kudos
DanteLee
Frequent Contributor

Ah always a couple different ways about it.

The "proper" way (in either case) would be to use pulldata + reversegeocode. Note: This consumes 0.04 credits for each reversegeocode statement that is run, so consider your survey traffic and credit limitations. This post has a good example for how to set up a single reversegeocode and use pulldata(@json,'..') for separate fields. See the attachment in the initial question - Survey123: Reverse Geocoding. At its most basic setup, it might look something like this in the calculation field to pull the city (assuming you're using the standard geocoder):

pulldata("@geopoint",${yourgeopointfieldname},"reversegeocode.address.City")‍‍

You could embed this within an if statement, or you could have a hidden calculation field if it helps you understand the process step-wise.

The alternate method I might suggest would be a compound if statement. In this case, it checks if the address is within Zlatar. (In other words, if address contains Zlatar AND it contains Bistrica, then it is not in Zlatar.)

if(contains(${address},'Zlatar') and contains(${address},'Bistrica'), 'no', 'yes')‍‍‍‍
0 Kudos
Arlington_CoGISMC
Occasional Contributor

What about if you are only using the web version? 

0 Kudos
DanteLee
Frequent Contributor

I believe using formulas is only supported through S123 Connect right now, but I wouldn't be surprised if it's in the pipeline for the web version

0 Kudos