Form validation with code

Struggling to validate uniqueness in a form. I have a page where I have a form. it adds data into a table. I wanna validate if one of the fields is NOT already existing (Clients table, i wanna be sure i don’t duplicate an already existing client by checking the client name) and since there’s no unique fields i see my only option is to use a code block… My thought is upon form submission i check the airtable and see if a record with such a field already exists and if yes, i display a small error somewhere and prevent the data from being inserted.
Kindly please help as I’ve struggled with everything from getting a hold of the input field to preventing submission…

Thanks

Hi @Dani411 welcome to the forum,

There are two ways to do this I think.

  1. If you do not need to validate in realtime (i.e. preventing the user from submitting the form) you can setup an automation in Airtable to find existing records that match the newly created record. If no record is found, do nothing. If an existing record is found, delete the newest one using a scripting step to call the Airtable API (Airtable does not have a “delete record” automation step for some reason).

  2. If you need real-time validation, you would need them to either check a list first, then add if none are found OR have them submit the needed criteria to determine duplicates in a form and redirect them to different pages using Webhooks and Webhook responses (using Zapier, Make, etc), checking for duplicates after the webhook has been triggered and redirecting them using webhook responses.

Thanks for the answer, i solved it myself eventually. (RT validation)
i added a code block in the form page

Here’s the code if it helps anyone else out there

<script>
Code Not Shown
</script>

Hi,

While it seems to be a solution this is actually not a solution at all and a major security breach.
Exposing in a custom code frontend an api key or a token is the worst practice ever and should not be used.
By doing this you can ruin your business in 5 minutes (There is no knowledge needed, not a single line of code).

Please people: never, ever expose your private API keys or tokens in a frontend code, this is the number 1 basic rule.
It’s not because it’s possible to use code that it should be done with code. There are consequences.
Also the input names might not be stable selectors, they can change from week to week.

Unfortunately the solution given by Patrick is the only real one (with a minimum security).

Feel free to use your own code if you want but it can’t be shown as a viable solution in the forum.

I will try to release a video later to show how easy it is to destroy an entire business by doing this.

Thanks for your understanding!

Oh i know about security. I don’t care because this is an internal tool for a very small business, virtually need 0 security beyond a login and nobody will know about the app unless i give them the link.
However it seems a little unfair to limit people’s access to knowledge because they might be stupid and hurt themselves. I think a warning about the code exposing API keys to frontend was sufficient and let people choose what they wanna do.
Cheers

You have a point. Feel free to re-add it.