fix(forms): skip required validation for conditionally hidden fields#7551
Open
faisalahammad wants to merge 1 commit into
Open
fix(forms): skip required validation for conditionally hidden fields#7551faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
pods_form_get_visible_objects() only checked the static 'hidden' property and missed fields hidden by conditional logic. As a result pods_form_validate_submitted_fields() ran required checks on hidden fields, blocking form submission even though the user never saw them. Now the function evaluates each field's conditional logic and skips fields whose rules resolve to hidden. Mirrors the existing filter behavior in PodsAPI::save_pod_item() so the standalone validator and the actual save path agree on which fields are active. Fixes pods-framework#7513
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pods_form_get_visible_objects()only checked the statichiddenproperty and missed fields hidden by conditional logic. As a resultpods_form_validate_submitted_fields()ran required checks on hidden fields, blocking form submission even though the user never saw them.This change evaluates each field's conditional logic and skips fields whose rules resolve to hidden. It mirrors the existing filter behavior in
PodsAPI::save_pod_item()so the standalone validator and the actual save path agree on which fields are active.Fixes #7513
Changes
includes/forms.php—pods_form_get_visible_objects()Before: the function only filtered out fields where the static
hiddenoption was true. Fields hidden by conditional logic passed through and were validated.After: before iterating, the function builds a
$field_valuesmap from the current submission, applying the same permission and hidden checks used elsewhere. Each field is then checked withField::is_visible( $field_values )and skipped if it resolves to hidden.Why: the existing save path in
PodsAPI::save_pod_item()already excludes conditionally hidden fields from the validation loop. The standalonepods_form_validate_submitted_fields()helper did not, so calling it on a form with required-but-hidden fields would returnWP_Erroreven though the save itself would have succeeded. Applying the same visibility logic here keeps both paths consistent.Testing
Reproduce the original issue from #7513.
original_authorandoriginal_urlare hidden whenoriginalis empty.[pods-form]shortcode.Test 1: submit with all three fields empty
originalreports a validation error; the two hidden fields passTest 2: submit with
originalfilled, the other two emptyoriginalso the conditional logic reveals the other two fieldsoriginal_authorandoriginal_urlnow report required errors as expectedTest 3: submit with all three filled