Is there any way to block links, or words for some page variables?

Hi again! I’m making an app which loads data from an API and where users can post data to the API. Now my problem is that I don’t want people posting unwanted website links in there and I want to block offensive words too. Is there any way to do that In appGyver?

If no:
How can I do it withing MariaDB?

Thanks in advance!

Hi,
If you have a list of things you are willing to block, you can use a REPLACE_ONE_REGEX* formula to censor those. CONTAINS can be used to filter links by checking if text contains “https” or “.com”

*Use REPLACE_ONE if you are unfamiliar with RegEx.

Hi, Thanks for your answer. Is there any way to add multiple page vars in a formula so I don’t need to do a list for every input field I have?

I am fairly sure you can only check one string at once, so one variable at a time.

Ok so if my post button’s logic is like this, where do I put the formulas?

Well, that strictly depends on your app’s personal logic/design. The way I see myself doing it is using the if statements to check if the text contains any unwanted content. Then, if it does not (false), I would move forward with submitting it.

Maybe, you could have a list of texts of your unwanted words and expressions as for example an app variable defined in the Composer pro with initial value.

Then on the text you want to check you could do something like this:

JOIN(MAP(SPLIT(texttosubmit, " "), IF(IS_IN_ARRAY(appVars.bannedwords, item), "******", item)," ") 

What this would do is it would create a list of words the text to submit has and then it would check each word against the list of banned words. If there is a banned word it would replace that word to asterisks if not then it returns the word that it checked. In the end to get back the text to submit it joins back all the words again.

Now this formula can be outplayed by adding any punctuation to the end of a banned word. So I have to think about it a little bit more to make it a really appropriate filter.

But use this formula where you set the text value to the create record or even before that, on the button tap event.

Hope this helps.

2 Likes

Okay so the update is here:

JOIN(MAP(SPLIT(texttosubmit, " "), IF(MAP<banned>(bannedwords, IF(CONTAINS(item, banned), true, false), "******", item)," ") 

Now here you might want to test this because of performance issues. As it is basically a loop in the loop with nested ifs, so I suggest setting this value before the create record to make sure it has time to run before the request is triggered.

As for your question where to put this logic. Put it between the delay and the create record. Or between the false output of your pageVars.location=="" and create record (but this would skip the 1 s delay so think about it).

Cheers for @Kirill_Leventcov, for the CONTAINS() suggestion, that helped to avoid the punctuation marks.

1 Like

Hi, Thanks for taking the time to answer, I really appreciate that! I’ll try it out asap!

I don’t really know how to integrate because when I try everything marks as red. (sorry i’m still pretty new to all of this)

Well… Yes… I mean you have to replace the “texttosubmit” to your specific property…
You have to create a bannedwords app variable. Populate that. And then use appVars.bannedwords there…
And it seems that I skipped a bracket (sorry for that, was typing riding the bike…)

And I think I have to do a little modification to the formula. I’ll write here soon.

1 Like

Ok, how can I create an app variable with multiple values tho? :sweat_smile:

Yeah, let me just rewrite the formula a little bit:

JOIN(MAP(SPLIT(data.post.texttosubmit, " "), IF(IS_IN_ARRAY(MAP<banned>(appVars.bannedwords, CONTAINS(item, banned)), true), "******", item)), " ")

Now this one doesn’t have bracket errors for sure. Please change the “data.post.texttosubmit” and “appVars.bannedwords” to your variable names.

As for the app variable creation check this set initial value for the app variable you can set as many as you need:

This surely works. So if you encounter any issues let me know:

So I have one problem, my post variables are stored in page variables which are later called in the create record process. When I try it, it always shows the error, even if I type hello. Can I just put the page variable for the input fields in the texttosubmit?


Okay. So do a “Set page variable” flow after the delay in your logic. Choose your text variable that you want to set. And then set its value to the formula above.

What are the error messages in the formula editor?

Just don’t set the value of the input field to this formula. Keep it that way “description”

That’s what they say:

Is this right?:

Oh man… Do you set this to a true/false? Sure it will throw error…
The full formula returns the text. The same description that the user types in, just changes the swearwords to “*****”…

If you need to check if it contains swearwords, then it would be a different formula… :frowning:

This one:

IS_IN_ARRAY(MAP(SPLIT(pageVars.description, " "), IS_IN_ARRAY(MAP<banned>(appVars.bannedwords, CONTAINS(item, banned)), true)), true)
1 Like

:smile:, I’m so sorry… Now it works tho! Thanks to you all for taking your time and help me!

image

1 Like