Unique Based on 2 Fields -

By: Craig Schneider | Asked: 07/26/2023
ForumsCategory: General questionsUnique Based on 2 Fields -
Craig SchneiderCraig Schneider asked 9 months ago

GOAL: To stop a user from creating duplicate entries.  

SIMPLIFIED FORM: FIELD [868] "Email 1" FIELD [869] "Email 2" FIELD [870] "Unique Check" - this field is a text field and has "Unique" & "Read Only" checked, Advanced = Default Value (Calculation) Text [868] [869]   This works great when and if the user put the emails in the proper order: EXAMPLE 1: Email 1: [email protected], Email 2: [email protected] (If the user tries to enter "Email 1: [email protected], Email 2: [email protected]" again the system "will not" allow it.

THE ISSUE: If the user enter the emails in a different order it will allow a duplicate to be created  EXAMPLE 2: Email 1: [email protected], Email 2: [email protected] (If the user tries to enter "Email 1: [email protected], Email 2: [email protected]" again the system "will" allow it.

THINGS WE TRIED: We tried to create a 2nd "Unique Check" field where we reversed the order of the Calculation Text [869] [868] - this did not work because as you change the oder of the emails it also changes the order of the formulas... Ugh!

SOMETHING WE THING WILL WORK (just can't crack the final code): One thing we thing would work is if we could sort the inputs of the 2 fields prior to adding them into the unique field, this would alway keep the order the same, in this example Ja[email protected], Jo[email protected], Jane would always be first in the unique checker field.   

QUESTION: Does anyone know how to sort a calculation field or sort a field prior to entry.  

ANOTHER THING THAT MIGHT WORK: If we could enter more than 1 entry into a single filed when filling out the form, in this case we could then enter "[868] [869]" and "[869] [868]" and this way the next time the unique checker looked for the emails both orders would be covered and it would not allow the entry of a duplicate.

1 Answers
Rob LeVineRob LeVine answered 9 months ago

What about using frm_validate_field_entry to check both fields against what's already in the database and throwing an error that way? Or frm_validate_entry

Craig SchneiderCraig Schneider replied 9 months ago

<p>Thanks, we actually did find a solution, unfortunately I can seem to post it in these comments for some reason (probably user error). We will also explore your possible solution, thanks for taking the time to help.</p>

Harry AbellHarry Abell replied 3 months ago

I am able to use Formidable Forms but do not know how / where to put PHP code. Also concerned that I could really mess things up trying. Is there a "safe" way for a novice to use php code in Formidable?

Rob LeVineRob LeVine replied 3 months ago

You can use this as a reference for how to use the developer hooks - https://formidableforms.com/knowledgebase/formidable-hooks/

In your example, you're not going to change any data (you're just comparing) so there's not any way you can mess things up. In general I certainly recommend using a dev or test server, rather than your production environment to test any new code.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community