Check all child entries don't exceed total field on parent form
GOAL
This code snippet ensures that the sum of all child entries in a Gravity Forms nested form does not exceed the total specified in the parent form. It validates the "Amount" field in child entries against the "Total" field in the parent form, preventing over-allocation of resources, budgets, or quotas. Shows a detailed, currency-formatted message if the attempt would exceed the total (Total, Used, Remaining, Attempted, Overage).
Features
- Validates child form entries to ensure the cumulative amount does not exceed the total in the parent form.
- Works with Gravity Forms Nested Forms to enforce limits across multiple child entries.
- Dynamically calculates totals from submitted child entries.
- Customizable field labels (e.g., "Amount" in child forms and "Total" in the parent form).
- Displays a validation message when the limit is exceeded, preventing submission errors.
Requirements
- Gravity Forms and Gravity Perks Nested Forms are required.
- GP Advanced Calculations is optional but recommended if the parent "Total" field uses a calculation. If Advanced Calculations is active and the target field has a calculation Formula, the formula is evaluated server-side during child validation.
- If you are not using a calculation, set a numeric default value on the parent "Total" field. If neither a calculation nor a numeric default value is present, this validation gracefully skips.
Configuration
$child_field_label
: label of the Number field on the child form that represents the amount to add (default: "Amount").$parent_field_label
: label of the Calculated/Number field on the parent that represents the total (default: "Total")
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.