Checking for empty string

I want to add a location address to a database entry (Formidable forms for Wordpress - but it could be any other). In some cases I know an exact address which is a secario input then. In most cases I just have the city from the database.

When creating the new entry I want to use the address if given, in all other cases the city name.

I tried to solve this with an if function but is always uses the city name.

Try #1
{{if(var.input.address=‘’; 2.location_city; var.input.address)}}

Try #2
{{if(var.input.address + “=” + emptystring; 2.location_city; var.input.address)}}

Try #3 (see screenshot)
{{if(length(var.input.address) + “=0”; 2.location_city; var.input.address)}}

What do I have to change to use if-function with strings?

Hello @jantheofel,

When doing your test to check for empty string, there’s a special keyword for that {{emptystring}}. You can find it on the string pill
image

Hope this helps!

2 Likes

Thanks @Donald_Mitchell!

I tried this (second try in my post but it didn’t work). :frowning:

I looked like this but always returns “location_city” even when the address is not empty.

makescreen2

Sorry about that, there’s a better way in this case. Try this:

image

How this works: “If address is NOT empty, use it, otherwise, use City”

1 Like

Hi Donald!

This is what I found myself a few moments ago and it works perfectly.
But I still wonder why the if-statements didn’t work. Do they just support numbers?

Jan

Just a couple notes about this one.
The If() function is looking for something that will give a true/false result.
The way you have it now results in some text, which is always true.

To compare your address to emptystring, convert address to a string by using toString({{address}}) and instead of typing in the = sign you need to use {{=}}.

Without the curly braces the equal sign is being treated as text.
With the curly braces, it is doing a comparison.

The final Field Value would look something like this:
if(toString({{address}}){{=}}{{emptystring}};{{2.location_city}};{{address}})

When you paste this into the field in Make the curly braces will go away and should result in your actual variables. The equal sigh should also turn green and look more like a variable than some text. I hope this makes sense!

4 Likes

Thanks! I try this next time I have to do string comparison. Here the ifempty-function is just perfect.