BrightLeaf Digital Code Snippet Library
Check out our growing library of code snippets for Gravity Forms!
Validate form for no duplicate values across X, Y, Z fields
Goal
This snippet ensures that specific groups of fields within a Gravity Forms form do not contain duplicate values. It allows you to define multiple sets of fields for validation, ensuring that no two fields within a group share the same value. If duplicates are found, a custom validation error message is displayed for each affected field.
Configuration
$forms: Each group is an array of field_id => 'error message'. If two or more fields in that
group have the same value, those fields will fail validation with the provided message.
Features
- Prevents Duplicate Values – Ensures that no two fields within specified groups have the same value.
- Supports Multiple Field Groups – Each form can have multiple sets of fields that must be unique within their group.
- Custom Error Messages – Define a specific validation error message for each field when duplicates are detected.
- Works Across Multiple Forms – The validation can be applied to different forms with custom field configurations.
- Supports Multi-Input Fields – Handles complex field types such as Name, Address, and Checkbox fields.
- Optimized Duplicate Detection – Uses efficient logic to check and flag duplicate values only when necessary.
This snippet is particularly useful for scenarios like ensuring unique user IDs, email addresses, product SKUs, or any other critical values in Gravity Forms.
Notes
- Multi‑input fields (Name, Address, Checkbox) are concatenated using a pipe (|) separator for
comparison to avoid accidental matches on spaces.
Install Using Code Snippets
This code is best installed directly on your site using the Code Snippets plugin.
Check Out the Code
Loading...
Stay Updated On This Snippet
Review this entry
You must be logged in to post a comment.