
If an old Contact Form 7 tutorial tells you to paste JavaScript into on_sent_ok or on_submit in Additional Settings, do not treat that as a current setup method. Those settings were removed in Contact Form 7 5.0. The useful task is to identify what the old code was supposed to do, then implement and verify a supported replacement.
This is a legacy migration checklist. It is especially relevant when inherited forms have stopped redirecting, stopped reporting events or now report them twice. Keep the migration narrow: one known form, one intended action and one owner for that action.
Inventory the original behavior
Before deleting anything, record the affected form, the old settings and the destination or tracker they referenced. Search your own reviewed theme assets, snippet manager and tag container for equivalent listeners. The same action may already have been moved elsewhere, leaving a retired setting that is harmless clutter while the real duplication lives in two active scripts.
Classify each action. A thank-you redirect, an analytics event, a visible confirmation and a server-side CRM operation have different requirements. Browser code is not a durable queue for business-critical lead creation. If the old snippet called a retired analytics API, changing only the CF7 trigger will not modernize the destination integration.
Choose the event that matches the intended outcome
The supported DOM events distinguish successful mail processing from validation, spam and mail failure outcomes. A success-specific action generally belongs on wpcf7mailsent. The broader wpcf7submit event also covers completed Ajax submissions with other outcomes. Review our event-selection guide before replacing the old setting mechanically.
For example, counting every completed submission response as a successful lead would mix invalid and rejected attempts into the success measure. Likewise, a browser success event does not establish final inbox delivery or that a CRM accepted a record. Define the reporting label in terms of the actual observed boundary.
Put the listener in a maintained JavaScript asset
Use your established plugin or child-theme asset workflow and WordPress’s supported enqueue mechanism. The following illustrative listener logs a diagnostic event for form ID 123. Replace that ID with the actual form ID and keep the example in a JavaScript file, not Additional Settings:
document.addEventListener('wpcf7mailsent', function (event) {
if (String(event.detail.contactFormId) !== '123') return;
console.info('CF7 mail processing completed', {
formId: event.detail.contactFormId,
instance: event.detail.unitTag
});
});
This code is a diagnostic illustration, not a complete analytics installation. It sends no event to an analytics service. Once you have observed the right trigger in staging, connect the intended action through that service’s current documented interface and its existing consent arrangement. Avoid logging names, email addresses or message contents when a form identifier is enough.
Scope the action to the right form instance
CF7 events bubble to the document, so a document-level listener can observe several forms. The form ID guard prevents a listener intended for a sales inquiry from acting on a support form. When the same form appears more than once on a page, inspect the instance information as well and decide whether the action should apply to every occurrence.
Ensure your script is included once. Repeated listener registration during modal initialization or navigation can produce multiple actions for one submission. Compare the asset inclusion and initialization path before adding extra deduplication code. Our multiple-form guide explains the distinction between a form definition and its page instances.
Retire the old action as one coordinated change
In staging, preserve a small record of the old setting, deploy the new listener through the normal reviewed workflow and remove the obsolete Additional Settings line. Also remove an older active listener only when you have identified it as the same behavior. Do not erase unrelated settings or rebuild the form merely to clear the warning.
If the action is a redirect, confirm the destination exists and that the redirect happens only for the intended success outcome. Follow our thank-you page guide for that behavior. If the action is analytics, inspect the outgoing event and its destination rather than counting a console message as tracking proof.
Verify outcomes and duplication
- Record a baseline with the old behavior and a synthetic inquiry in a safe environment.
- Submit one valid inquiry and verify one intended action for the target form.
- Submit invalid input and confirm a success-only action does not run.
- Review other outcomes using controlled fixtures or an approved test setup, without disrupting production mail.
- Submit a different form on the same page and check the form guard.
- Reload, reopen any form modal and repeat to detect repeated registration.
Clear or refresh only the relevant page and asset caches through the site’s normal process. If the browser still loads an old script, inspect the actual asset response before changing form configuration again. Separate “listener did not load” from “listener loaded but chose a different outcome.”
Keep an honest measurement record
Document the migration date, form ID, old action, new asset and verified destination. An apparent jump after repair can reflect restored instrumentation rather than more inquiries. Our GA4 and Tag Manager guide helps define a separate analytics setup.
For WordPress submission trends and statistics, review the free Svetlik Analytics for Contact Form 7. It does not replace verification of your custom redirect or external tracker. Keep a completed migration note so the next maintainer can identify the single active implementation without repeating the archaeology.
