Skip to content

Support repeater paths inside embedded forms - #3602

Draft
Crabcyborg wants to merge 11 commits into
masterfrom
fix/embedded-repeaters
Draft

Crabcyborg wants to merge 11 commits into
masterfrom
fix/embedded-repeaters

Conversation

@Crabcyborg

Copy link
Copy Markdown
Contributor

Support repeater fields inside embedded forms by preserving the full nested item_meta path when reading submitted values, checking whether values were posted, and writing validated values. Resolve nested frontend field IDs, including Other inputs and combo subfields, while ignoring form and row metadata.

Add FrmEntryMetaPathHelper and regression tests for nested reads and writes, malformed paths, sibling-row preservation, backslashes, and legacy parent arguments. The generated frontend script matches a fresh build. These are the existing local changes, separated without behavior changes.

This is the Lite companion to https://github.com/Strategy11/formidable-pro/pull/6881. The field lifecycle hooks for the parent/child relations index remain separate in #3595.

Validation

  • Lite PHPUnit: 947 tests, 4,845 assertions, no failures. The runner reports 3 skipped tests, 3 incomplete tests, 99 notices, and one configuration deprecation.
  • Companion Pro branch: 13 embedded repeater tests with 42 assertions pass. Its AJAX regression passes separately with 4 assertions. The harness verifies that it loads the companion branch.
  • Source and generated JavaScript each pass 13 field ID checks. The generated file matches Closure Compiler output.
  • PHP syntax, PHPCS, PHP-CS-Fixer, Rector, scoped Mago lint, full-plugin PHPStan, Oxlint, typos, and whitespace checks pass. ESLint exits successfully with four warnings on unchanged lines. Full-plugin Mago analysis exits successfully with two warnings outside this change.
  • Full-plugin Psalm reports four errors. An isolated checkout of unchanged master reports the same four errors, concerning WordPress stubs and an existing deprecated function.
  • Reviewed the changed submission paths and frontend handling. No new security concern was identified.

Remaining verification

Keep this draft alongside the Pro draft until browser verification covers adding and removing nested rows, required validation, conditional logic, Other choices, totals, page navigation, and saved-entry editing. Browser verification was not run in this session.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@deepsource-io

deepsource-io Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 85479d8...9f6bb2a on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Dec 2, 2026 1:44p.m. Review ↗
JavaScript Dec 2, 2026 1:44p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

);
$args = array( 'item_meta_path' => array( 10, 0, 20, 0 ) );
$field = (object) array( 'id' => 30 );
$this->assertTrue( FrmEntriesHelper::value_is_posted( $field, $args ), 'A field at the nested path should be posted.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMetaPathHelper::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

$args = array( 'item_meta_path' => array( 10, 0, 20, 0 ) );
$field = (object) array( 'id' => 30 );
$this->assertTrue( FrmEntriesHelper::value_is_posted( $field, $args ), 'A field at the nested path should be posted.' );
$this->assertSame( 'First', FrmEntriesHelper::get_posted_meta( 30, $args ), 'The helper should read the requested nested row.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMetaPathHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertTrue( FrmEntriesHelper::value_is_posted( $field, $args ), 'A field at the nested path should be posted.' );
$this->assertSame( 'First', FrmEntriesHelper::get_posted_meta( 30, $args ), 'The helper should read the requested nested row.' );
FrmEntriesHelper::set_posted_value( $field, 'Updated', $args );
$this->assertSame( 'Updated', $_POST['item_meta'][10][0][20][0][30], 'The requested field should be updated.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMetaPathHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertSame( 'First', FrmEntriesHelper::get_posted_meta( 30, $args ), 'The helper should read the requested nested row.' );
FrmEntriesHelper::set_posted_value( $field, 'Updated', $args );
$this->assertSame( 'Updated', $_POST['item_meta'][10][0][20][0][30], 'The requested field should be updated.' );
$this->assertSame( 'Second', $_POST['item_meta'][10][0][20][1][30], 'Other rows should be preserved.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMetaPathHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

FrmEntriesHelper::set_posted_value( $field, 'Updated', $args );
$this->assertSame( 'Updated', $_POST['item_meta'][10][0][20][0][30], 'The requested field should be updated.' );
$this->assertSame( 'Second', $_POST['item_meta'][10][0][20][1][30], 'Other rows should be preserved.' );
$this->assertSame( wp_slash( 'A \\ B' ), $_POST['item_meta'][40], 'Unrelated values should retain their existing slashes.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMetaPathHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$_POST['item_meta'] = array( 10 => 'malformed' );
$args = array( 'item_meta_path' => array( 10, 0, 20, 0 ) );
$field = (object) array( 'id' => 30 );
$this->assertFalse( FrmEntriesHelper::value_is_posted( $field, $args ), 'A malformed parent should not count as a posted field.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMetaPathHelper::assertFalse()


The method you are trying to call is not defined, which can result in a fatal error.

$args = array( 'item_meta_path' => array( 10, 0, 20, 0 ) );
$field = (object) array( 'id' => 30 );
$this->assertFalse( FrmEntriesHelper::value_is_posted( $field, $args ), 'A malformed parent should not count as a posted field.' );
$this->assertSame( '', FrmEntriesHelper::get_posted_meta( 30, $args ), 'A malformed parent should return an empty value.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMetaPathHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertFalse( FrmEntriesHelper::value_is_posted( $field, $args ), 'A malformed parent should not count as a posted field.' );
$this->assertSame( '', FrmEntriesHelper::get_posted_meta( 30, $args ), 'A malformed parent should return an empty value.' );
FrmEntriesHelper::set_posted_value( $field, 'Created', $args );
$this->assertSame( 'Created', $_POST['item_meta'][10][0][20][0][30], 'Writing should initialize missing parent arrays.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMetaPathHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

'item_meta_path' => array(),
);
FrmEntriesHelper::set_posted_value( (object) array( 'id' => 30 ), 'Legacy row', $args );
$this->assertSame( 'Legacy row', $_POST['item_meta'][10][0][30], 'An empty path should preserve existing repeater arguments.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMetaPathHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

@Crabcyborg Crabcyborg added this to the 7.1 milestone Oct 29, 2026
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Oct 29, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve, with two non-blocking notes below.

Live before/after (preview env, Lite + Pro companion #6881 loaded; same seeded form: parent form → embedded form → repeater with a required text field):

  • Base (master Lite + master Pro): the embedded repeater's input renders as item_meta[7][0][6], outside the embed's item_meta[8][0]... path. A submit with the field filled saved the repeater rows as a top-level 7 meta on the parent entry instead of under the embed. A direct FrmEntryValidate::validate call with the correctly nested payload returned a false REQUIRED_MSG for a filled field and created a phantom item_meta[7] key.
  • PR (#3602 + #6881): input renders as item_meta[8][0][7][0][6]. Empty submit shows the required error on the right field (frm_field_6-7-0_container, screenshot below). Filled submit saves with no error, and the entry chain nests correctly (parent field 8 → embed entry → repeater entry → hello). Validate with the filled nested payload returns no errors and no phantom key; the empty payload errors only on the empty row.
  • Backslash loss in a sibling row (A \ B → A B) happens identically on base, so it is not a regression from this PR.

Required error on the embedded repeater field, PR branch

Not exercised: add/remove rows, conditional logic, Other choices, combo subfields, totals, page navigation, editing a saved entry, multiple rows through the browser. The new JS branch was only hit for a plain text field. Run only against the PR's own two-PR pairing: Lite alone changes nothing (nothing in Lite sets item_meta_path), and Pro #6881 needs this Lite helper, so this should merge first. CI is all skipping because the PR is a draft, so PHPUnit/PHPCS/PHPStan have not run on GitHub; I read the diff and the source but did not run the PHPUnit file or the lint tools myself.


// Check if there are any other posted "other" values for this field.
if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
$path = ! empty( $args['item_meta_path'] ) ? $args['item_meta_path'] : array( $args['parent_field_id'], $args['key_pointer'] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: the early return at line 535 (if ( ! $args['parent_field_id'] ) { return; }, not in this diff) is the legacy argument, but the lines below it are now path-aware. A caller that passes only item_meta_path (the way Pro's new code calls get_posted_meta) hits an undefined-index notice here, and with parent_field_id empty it returns before the path is ever used. Pro #6881 happens to pass both today. Make that guard match the path logic so the two can't drift: if ( empty( $args['parent_field_id'] ) && empty( $args['item_meta_path'] ) ) { return; }.

The "Other" branch also has no test; test_FrmEntryMetaPathHelper covers read/write/malformed/legacy but not set_other_repeating_vals with a path. A short case with $_POST['item_meta'][10][0]['other'][30] would cover it.

Comment thread classes/helpers/FrmAppHelper.php Outdated
$value = wp_unslash( $_POST[ $args['param'] ] );
$value = $_POST[ $args['param'] ];

foreach ( $args['path'] ?? array() as $key ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: path is a new option on a widely used function, but it isn't in $defaults or the docblock, and FrmEntryMetaPathHelper::get_posted_row() is its only caller. Either add 'path' => array() to $defaults and document it, or keep the walk inside FrmEntryMetaPathHelper so get_simple_request stays as it was. The existing contract (wp_unslash after the lookup) is preserved either way.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Oct 29, 2026
@Crabcyborg Crabcyborg modified the milestones: 7.1, 7.2 Nov 11, 2026
Crabcyborg and others added 3 commits November 18, 2026 15:55
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the item_meta path walk out of FrmAppHelper::get_simple_request()
so its options stay unchanged. Let set_other_repeating_vals() accept a
caller that passes only item_meta_path, and cover the nested Other value
with a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rebuild the compiled bundles from the merged sources instead of merging
them by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franky-the-going-merry franky-the-going-merry Bot added franky-working Franky is actively reviewing this and removed franky-working Franky is actively reviewing this labels Nov 19, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve, with one non-blocking note. Re-review of the whole PR at 70fa31b (my Approve was at dcc4e06). Since then: two master merges and b71c8d6, which moves the path walk out of get_simple_request() into FrmEntryMetaPathHelper::get_posted_row() and makes set_other_repeating_vals() path-aware. That closes both notes from my last round.

Live before/after (fresh preview env, Lite #3602 at 70fa31b + Pro #6881 at fe6a48f vs. both merge-bases; parent form -> embedded form -> repeater with a required text field):

  • Base: the repeater input renders as item_meta[10][0][11], outside the embed path item_meta[12][0]. A filled submit saves a raw serialized array on the parent entry (field 10 = a:3:{form,row_ids,0 => [ '', 11 => 'hello' ]}) and creates no embed or row entries.
  • PR: input renders as item_meta[12][0][10][0][11]. Empty submit shows "Item cannot be blank." on frm_field_11-10-0_container (the right nested field). Filled submit saves with no error, and the entry chain nests: parent entry 5 -> embed entry 4 (form 5) -> row entry 3 (form 6) with field 11 = hello.

Tests run: vendor/bin/phpunit tests/phpunit/entries/test_FrmEntryMetaPathHelper.php at 70fa31b in the wordpress-develop harness -> OK (4 tests, 11 assertions). tests/phpunit/entries OK (51 tests, 295 assertions); test_FrmAppHelper.php OK (32 tests, 147 assertions). With the new empty( $args['item_meta_path'] ) guard term removed from set_other_repeating_vals(), the new Other-value test errors; restored, it passes. CI is all skipping (draft), so PHPUnit/PHPCS/PHPStan did not run on GitHub. I did not run PHPCS/PHPStan; php -l is clean on both PHP files.

Not exercised: add/remove rows in the browser, conditional logic, Other and combo fields live (Other is covered by the unit test only), totals, page navigation, editing a saved entry. The server-side required message came back on the correct container, but I did not isolate whether the new getFieldId JS branch ran (the preview env can serve a stale formidable.min.js); the min file does contain the new matcher and differs from master only by Closure reflow plus this change. code-review/security-review/simplify were not run; I read the diff directly. No new security surface: values are still unslashed once and sanitized downstream, and the path is only used as array keys.

  • FrmEntriesHelper.php:540: get_posted_row() now runs for every non-empty field in a repeater, before the cheap other option check (non-blocking, inline).

Comment on lines +539 to 544
$path = ! empty( $args['item_meta_path'] ) ? $args['item_meta_path'] : array( $args['parent_field_id'], $args['key_pointer'] );
$row = FrmEntryMetaPathHelper::get_posted_row( $path );

if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $row['other'][ $field->id ] ) ) {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking efficiency note. maybe_set_other_validation() calls this for every non-empty field in a repeater row, and get_posted_row() runs wp_unslash() over the whole $_POST['item_meta'] each time (via get_simple_request()). Before this PR the legacy repeater path was a single isset() on item_meta[parent][pointer]['other'][field]. With a big repeater that is one full-array map_deep per field per row. The row only matters when the field has the other option, so check that first and read the row after:

Suggested change
$path = ! empty( $args['item_meta_path'] ) ? $args['item_meta_path'] : array( $args['parent_field_id'], $args['key_pointer'] );
$row = FrmEntryMetaPathHelper::get_posted_row( $path );
if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $row['other'][ $field->id ] ) ) {
return;
}
if ( ! FrmField::is_option_true( $field, 'other' ) ) {
return;
}
$path = ! empty( $args['item_meta_path'] ) ? $args['item_meta_path'] : array( $args['parent_field_id'], $args['key_pointer'] );
$row = FrmEntryMetaPathHelper::get_posted_row( $path );
if ( ! isset( $row['other'][ $field->id ] ) ) {
return;
}

Same behavior, no unslash for fields without Other.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 19, 2026
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 23, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. Re-review of the whole PR at 8a0bdff (my last Approve was at 70fa31b). The only change since is 8a0bdff: set_other_repeating_vals() now checks the cheap other option first, before get_posted_row(). That closes my one non-blocking note, and the logic is otherwise identical.

Live before/after (fresh preview env, Lite #3602 at 8a0bdff + Pro #6881 at fe6a48f vs. both merge-bases 7f27c411a / 40663bd51; parent form -> embedded form -> repeater with a required text field):

  • Base: the repeater input renders as item_meta[6][0][7], outside the embed path item_meta[8][0]. A filled submit saves the parent entry with field 6 = raw serialized array (a:3:{form, row_ids, 0 => [ '', 7 => 'hello' ]}) and creates no embed or row entries.
  • PR: the input renders as item_meta[8][0][6][0][7]. Empty submit shows "Item cannot be blank." with the error link pointing at #frm_field_7-6-0_container (the right nested field). Filled submit succeeds, and the chain nests: parent entry 3 (form 4) -> embed entry 2 (form 2) -> row entry 1 (form 3) with field 7 = hello.

Tests run: vendor/bin/phpunit tests/phpunit/entries/test_FrmEntryMetaPathHelper.php at 8a0bdff in the wordpress-develop harness -> OK (4 tests, 11 assertions). tests/phpunit/entries -> OK (51 tests, 295 assertions). With the other guard term removed from set_other_repeating_vals(), the new Other-value test errors (Undefined array key "other"); restored, it passes. php -l is clean on both PHP files. CI is all skipping (draft), so PHPUnit/PHPCS/PHPStan did not run on GitHub, and I did not run PHPCS/PHPStan.

Not exercised: add/remove rows in the browser, conditional logic, Other and combo fields live (Other is covered by the unit test only), totals, page navigation, editing a saved entry, and the new getFieldId JS branch in the browser (the live check was a server-side submit). Pairing note: Lite alone changes nothing, and Pro #6881 needs this Lite helper, so this should merge first. code-review/security-review/simplify were not run; I read the full diff directly. No new security surface: values are read from $_POST through get_simple_request, and the path is only used as array keys.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 23, 2026
@Crabcyborg Crabcyborg removed this from the 7.2 milestone Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant