Docs

Ninja Forms Integration

3 min readUpdated June 22, 2026

Ninja Forms is a WordPress form builder with a Backbone/Marionette-based frontend. Because Ninja Forms renders its submit button via JavaScript rather than PHP templates, WP Smart Consent uses a script-based injection approach for the consent checkbox.

Enabling the Integration#

In the WP Smart Consent dashboard, go to Form Sources and toggle Ninja Forms on. Per-form behavior is then configured from the Ninja Forms settings page added by WP Smart Consent.

Screenshot of the "Ninja Forms" settings in a web interface. The section is inactive and shows tabs for "General" and "Collect fields." Options include enabling Ninja Forms and a green "Save Ninja Forms" button at the bottom.

Per-Form Settings#

Ninja Forms stores forms in its own custom database tables rather than as WordPress posts, so there is no standard post list screen to add row actions to. WP Smart Consent registers a submenu page under the Ninja Forms admin menu that serves as both a form list and per-form settings page. Go to Ninja Forms → WP Smart Consent to see all your forms. Click any form to open its settings.

Form Type#

Contact form — Ninja Forms uses a Backbone/Marionette frontend that renders the submit button into a .submit-container div via JavaScript. There is no PHP hook that fires before the rendered submit button. WP Smart Consent hooks into ninja_forms_display_init, which fires inside the PHP display template before Ninja Forms’ JavaScript mount point, and emits an inline script that listens for Ninja Forms’ own nfFormReady document event. Once that event fires, the script inserts the consent checkbox div immediately before the .submit-container element.

The checkbox input sits outside Ninja Forms’ own field namespace. Ninja Forms serializes only its own field ID-to-value pairs into a JSON blob for submission. The WPSC checkbox arrives as a plain $_POST key (wpsc_optin=1) alongside the Ninja Forms JSON payload.

Newsletter form — no checkbox is injected. Every successful submission is treated as an opt-in and forwarded automatically.

Collect Fields#

Map the form’s fields to standard WPSC data fields. Ninja Forms identifies each field by its integer field ID — for example field 3 or field 12. The dropdown in the settings page is populated by reading directly from Ninja Forms’ nf3_fields database table for that form. Field value lookups at submission time use a direct integer cast against the $data['fields'] array, making them O(1).

Email — required. First name, Last name, Phone, Company, Country — all optional.

Extra Fields#

Below the standard field selectors, the Extra fields section lets you map any additional Ninja Forms field to a custom CRM key. Select the form field on the left and enter the CRM key on the right. That key is sent alongside the standard contact data on every opt-in.

Submission Hook#

WP Smart Consent listens on ninja_forms_after_submission, which fires after all configured Ninja Forms actions have been processed for a valid submission. Because Ninja Forms calls wp_die() on errors before this hook fires, it is effectively success-only. WP Smart Consent also checks $data['errors'] defensively before processing.

Troubleshooting#

WP Smart Consent settings not appearing — go to Ninja Forms → WP Smart Consent. If the submenu item is missing, confirm the Ninja Forms integration is enabled in the WPSC dashboard and that Ninja Forms is active.

Checkbox not appearing on the form — the checkbox is injected via a script listening for the nfFormReady event. If this event does not fire — for example if Ninja Forms’ JavaScript fails to load or a JavaScript error occurs earlier on the page — the checkbox will not be inserted. Check the browser console for errors.

Consent value not captured — the wpsc_optin value arrives as a plain $_POST key rather than inside Ninja Forms’ field data. Confirm nothing on the page is stripping extra POST parameters before the submission reaches WordPress.

Wrong field values forwarded — Ninja Forms field IDs are integers assigned at field creation time. If a field was deleted and re-added in the form builder, its ID changes. Re-open the WP Smart Consent settings at Ninja Forms → WP Smart Consent and re-select the correct fields.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only