Skip to content

Support repeater paths inside embedded forms - #3602

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

Crabcyborg wants to merge 2 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 ab4ee48...a4feb25 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 ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Nov 18, 2026 7:55p.m. Review ↗
JavaScript Nov 18, 2026 7:55p.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.

$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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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