Skip to content

New spam settings section in form settings#3179

Merged
Crabcyborg merged 13 commits into
masterfrom
new_spam_settings_section_in_form_settings
Jul 14, 2026
Merged

New spam settings section in form settings#3179
Crabcyborg merged 13 commits into
masterfrom
new_spam_settings_section_in_form_settings

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This update aims to pull all spam settings to a single location in form settings. It includes field-level settings (adding a captcha field), and a readonly display for Global Settings with a link to make the Global spam settings easier to access.

  1. Spam settings are now a new section in form settings, instead of being under "On Submit" in "General".
  2. A new "Include Captcha in this form" setting has been added that syncs with the presence of a Captcha field. It adds / removes Captcha fields when toggled. This is a redundant setting to make it easier to find Captcha settings at a form level. When added, this should be the last field in the form, before the submit button. If Captcha keys are not set, this should be disabled.
  3. A new readonly table of Global settings is now visible in the Spam settings area.
Screenshot 2026-07-07 at 12 46 21 PM

There's a note in the old location to make them easier to locate for users who expect the old location.

Screenshot 2026-07-07 at 12 46 31 PM

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a dedicated Spam settings section/tab for forms, including a “Global Spam Settings” overview and an Include Captcha in this form option (with guidance/warnings when captcha isn’t configured globally).
  • Bug Fixes

    • Improved admin tab switching so the Spam section activates and scrolls into view reliably.
    • Updated warning behavior so only the relevant captcha warnings toggle based on the checkbox state.
  • Style

    • Added styling for the new Spam settings layout and status icons, plus a minor settings-page note about the moved Spam section.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9b3b8d38-212a-42e6-b446-ad83de85af1c

📥 Commits

Reviewing files that changed from the base of the PR and between 4eec840 and 93a0de1.

📒 Files selected for processing (4)
  • classes/controllers/FrmFormsController.php
  • css/frm_admin.css
  • js/formidable_admin.js
  • js/src/admin/admin.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • css/frm_admin.css
  • js/src/admin/admin.js

📝 Walkthrough

Walkthrough

Adds a consolidated Spam settings tab with CAPTCHA controls and global spam status indicators, backend CAPTCHA field creation/removal during form updates, an Advanced settings redirect, and supporting JavaScript, SCSS, and regenerated admin assets.

Changes

Spam Settings Consolidation and CAPTCHA Management

Layer / File(s) Summary
CAPTCHA field handling on settings save
classes/controllers/FrmFormsController.php
update_settings() reads frm_include_captcha and creates or destroys the form CAPTCHA field through handle_captcha_field().
Spam settings tab registration and renderer
classes/controllers/FrmFormsController.php
Registers the Spam tab, adds spam_settings(), and retains render_spam_settings() as a deprecated stub.
Consolidated Spam settings view
classes/views/frm-forms/spam-settings.php, classes/helpers/FrmHtmlHelper.php
Loads anti-spam modules, renders CAPTCHA controls and warnings, displays global spam settings with readonly icons, and links to global CAPTCHA settings.
Advanced settings redirect
classes/views/frm-forms/settings-advanced.php
Replaces inline spam settings with a notice and jump link to the Spam section.
Admin interaction and styling
js/src/admin/admin.js, resources/scss/admin/components/settings/_form-settings.scss
Adds Spam tab navigation, CAPTCHA warning toggling, forced-warning preservation, and Spam settings styles.
Generated admin assets
css/frm_admin.css, js/formidable_admin.js
Regenerates the minified admin stylesheet and JavaScript bundle.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SpamSettingsView
  participant FrmFormsController
  participant FrmField

  User->>SpamSettingsView: toggle Include CAPTCHA
  User->>FrmFormsController: save settings with frm_include_captcha
  FrmFormsController->>FrmFormsController: update_settings()
  FrmFormsController->>FrmFormsController: handle_captcha_field(form_id, include_captcha)
  FrmFormsController->>FrmField: get_all_for_form(form_id)
  alt CAPTCHA requested and missing
    FrmFormsController->>FrmField: create CAPTCHA field before submit
  else CAPTCHA not requested and present
    FrmFormsController->>FrmField: destroy CAPTCHA field
  end
  FrmFormsController-->>User: updated settings
Loading

Possibly related PRs

Suggested reviewers: garretlaxton

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding a new Spam settings section within form settings.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch new_spam_settings_section_in_form_settings

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.44.1)
js/formidable_admin.js

ast-grep timed out on this file


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

Comment @coderabbitai help to get the list of available commands.

@deepsource-io

deepsource-io Bot commented Jul 7, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in f6eb839...93a0de1 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 Jul 14, 2026 5:40p.m. Review ↗
JavaScript Jul 14, 2026 5:40p.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.

@Crabcyborg
Crabcyborg requested a review from garretlaxton July 7, 2026 15:49

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
classes/views/frm-forms/spam-settings.php (2)

101-110: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Add rel="noopener" to the target="_blank" link.

Other target="_blank" links in this codebase (e.g. FrmFormsController::get_form_too_long_docs_url() usage) include rel="noopener". This link omits it.

🔒️ Proposed fix
 		'<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings&t=captcha_settings' ) ) . '" target="_blank">',
+		'<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings&t=captcha_settings' ) ) . '" target="_blank" rel="noopener">',
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@classes/views/frm-forms/spam-settings.php` around lines 101 - 110, The link
in the spam settings notice opens a new tab via target="_blank" but is missing
rel="noopener". Update the anchor markup built in the printf call in the spam
settings view so the generated link includes rel="noopener", matching the
existing pattern used elsewhere such as in FrmFormsController-related external
links.

39-50: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate captcha-field lookup logic.

This loop re-implements the same "find captcha field by iterating form fields" logic that FrmFormsController::handle_captcha_field() already performs. Extracting a shared helper (e.g. on FrmField) would keep both call sites in sync if the captcha field type or lookup ever changes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@classes/views/frm-forms/spam-settings.php` around lines 39 - 50, The
captcha-field lookup is duplicated here and in
FrmFormsController::handle_captcha_field(), so update this block to use a shared
helper instead of iterating form fields directly. Add or reuse a single FrmField
helper for finding the captcha field by form ID, then call that helper from both
FrmFormsController::handle_captcha_field() and the spam-settings view so the
lookup logic stays consistent if the captcha type changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@classes/controllers/FrmFormsController.php`:
- Around line 306-346: The captcha creation branch in handle_captcha_field()
calls FrmField::create() with an incomplete payload, missing the default options
and field_options that FrmField::create() expects. Update the array passed to
FrmField::create() in the include-captcha path to mirror the default field
payload used by create_submit_button_field(), so the captcha field is created
with the same required defaults and does not trigger warnings or save incomplete
data.

---

Nitpick comments:
In `@classes/views/frm-forms/spam-settings.php`:
- Around line 101-110: The link in the spam settings notice opens a new tab via
target="_blank" but is missing rel="noopener". Update the anchor markup built in
the printf call in the spam settings view so the generated link includes
rel="noopener", matching the existing pattern used elsewhere such as in
FrmFormsController-related external links.
- Around line 39-50: The captcha-field lookup is duplicated here and in
FrmFormsController::handle_captcha_field(), so update this block to use a shared
helper instead of iterating form fields directly. Add or reuse a single FrmField
helper for finding the captcha field by form ID, then call that helper from both
FrmFormsController::handle_captcha_field() and the spam-settings view so the
lookup logic stays consistent if the captcha type changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1e2acb21-b7f9-4fc7-a9a0-f6fab4062cab

📥 Commits

Reviewing files that changed from the base of the PR and between f92019b and 79522a9.

📒 Files selected for processing (8)
  • classes/controllers/FrmFormsController.php
  • classes/helpers/FrmHtmlHelper.php
  • classes/views/frm-forms/settings-advanced.php
  • classes/views/frm-forms/spam-settings.php
  • css/frm_admin.css
  • js/formidable_admin.js
  • js/src/admin/admin.js
  • resources/scss/admin/components/settings/_form-settings.scss

Comment thread classes/controllers/FrmFormsController.php
@garretlaxton

Copy link
Copy Markdown

I'm seeing the following deprecated message in the captcha field description when I enable the Include Captcha in this form option to add a captcha field.

Deprecated</b>: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /Users/garret/Local Sites/ff/app/public/wp-content/plugins/formidable-forms/classes/helpers/FrmAppHelper.php on line 2559

@Crabcyborg

Crabcyborg commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

I'm seeing the following deprecated message in the captcha field description when I enable the Include Captcha in this form option to add a captcha field.

Deprecated</b>: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /Users/garret/Local Sites/ff/app/public/wp-content/plugins/formidable-forms/classes/helpers/FrmAppHelper.php on line 2559

Thank you @garretlaxton!

The code for creating the captcha field wasn't very complete. It's been updated to go through the proper functions. This should be fixed now.

The old captcha would likely still throw the same issues, so I'd uncheck, save, and check it again.

@garretlaxton garretlaxton left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks good now!

@Crabcyborg

Copy link
Copy Markdown
Contributor Author

Thank you @garretlaxton!

🚀

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
classes/controllers/FrmFormsController.php (2)

287-290: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve the existing captcha field when the checkbox is disabled (classes/controllers/FrmFormsController.php:288-289). When frm_include_captcha is missing or 0 because the control is disabled in the Spam view, this path still reaches FrmField::destroy(). Saving unrelated form settings can remove an existing captcha field; only treat an explicit user uncheck as removal.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@classes/controllers/FrmFormsController.php` around lines 287 - 290, Update
the captcha inclusion flow around FrmFormsController::handle_captcha_field so a
missing or disabled frm_include_captcha value preserves the existing captcha
field. Only invoke captcha removal when the request explicitly indicates the
user unchecked the control, while retaining creation behavior for an enabled
checkbox.

321-325: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Handle all CAPTCHA fields, not just the first match. The handler only records and deletes the first CAPTCHA field ID. If duplicate CAPTCHA fields are present, unchecking leaves the others in place and the form setting no longer matches the form contents. Collect all matching IDs or enforce a single-CAPTCHA invariant.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@classes/controllers/FrmFormsController.php` around lines 321 - 325, Update
the CAPTCHA field handling in FrmFormsController to process every field whose
type is 'captcha' rather than breaking after the first match. Collect all
matching field IDs and ensure the subsequent unchecking/removal logic deletes
each one, keeping the form setting synchronized with its contents.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@classes/controllers/FrmFormsController.php`:
- Around line 287-290: Update the captcha inclusion flow around
FrmFormsController::handle_captcha_field so a missing or disabled
frm_include_captcha value preserves the existing captcha field. Only invoke
captcha removal when the request explicitly indicates the user unchecked the
control, while retaining creation behavior for an enabled checkbox.
- Around line 321-325: Update the CAPTCHA field handling in FrmFormsController
to process every field whose type is 'captcha' rather than breaking after the
first match. Collect all matching field IDs and ensure the subsequent
unchecking/removal logic deletes each one, keeping the form setting synchronized
with its contents.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6e1101db-de50-45d0-bd26-ca5ac0652882

📥 Commits

Reviewing files that changed from the base of the PR and between 79522a9 and 4eec840.

📒 Files selected for processing (6)
  • classes/controllers/FrmFormsController.php
  • classes/helpers/FrmHtmlHelper.php
  • classes/views/frm-forms/spam-settings.php
  • css/frm_admin.css
  • js/formidable_admin.js
  • js/src/admin/admin.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • js/src/admin/admin.js
  • classes/views/frm-forms/spam-settings.php

@Crabcyborg
Crabcyborg merged commit 0b2ae8c into master Jul 14, 2026
20 of 22 checks passed
@Crabcyborg
Crabcyborg deleted the new_spam_settings_section_in_form_settings branch July 14, 2026 17:49
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.

2 participants