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…
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).
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.
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.
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
It’s a shame this doesn’t exist built in still, but it’s possible via a workflow at least if you’re using softr db. At a high level, your steps would look like:
In your database, add a formula column that converts your unique value to all caps using UPPER(). So, for example, if you are doing this for Company Name column, you’ll need a Company Name AllCaps col to check against.
Create a form or action in the application that triggers a custom workflow
The first step of that workflow will be the form submitted action.
The second step should be a text transform to convert the company name field inputted by the form to all caps.
Then add a softr db search for multiple records and look for any Company records where the Company Name All Caps = the created record’s company name in all caps (output of the modules 3 and 4 used for the search)
Then add a custom code module with simple code to spit out the length of results found
Then add a branch.. if the length is > 1 then it means you have a duplicate on your hands.. you would want a step to delete the most recently created record (using the ID of the company record that triggered this whole workflow) and then show the user an error
For the other side of the branch, ie if length is less than or equal to 1, you can show them a confirmation message.
I came across this older discussion and wanted to add that for enhanced security, consider using server-side checks with cloud functions to handle your validations. This way, API keys stay secure, and you can perform comprehensive validation before data hits your primary systems. Anyone implemented cloud functions for form validation? Curious to hear how it went for you!