A question was asked on the WP Business Builders Facebook group about adding dynamic redirection to the self for on-page login pages i.e for login forms mainly.
I actually solved this one a while ago for another of my plugins, so I thought I’d turn that into a quick, simple article to add the option.

For another project I was working on, Response for SureForms, I already knew how to do this; it was one of the initial pieces of work I needed to solve for the response, i.e adding another option for my responses, as I didn’t want to use Ottokit for dynamic forms; I wanted to use FlowMattic.
So, using this and how a form works and the docs, I was able to produce a new snippet that does exactly what was asked for, allowing a form to submit back to the page it was inserted on.
The Snippet
<?php
/**
* SureForms – Dynamic Redirect to Current Page
*/
defined('ABSPATH') || exit;
/**
* 1. Add confirmation option in SureForms admin
*/
add_action('admin_enqueue_scripts', function () {
wp_enqueue_script('wp-hooks');
wp_enqueue_script('wp-i18n');
wp_add_inline_script('wp-i18n', <<<JS
document.addEventListener("DOMContentLoaded", function () {
const hooks = wp.hooks;
const i18n = wp.i18n;
hooks.addFilter(
"srfm.formConfirmation.confirmationType.inputs",
"responsefsf/dynamic-redirect",
(inputs) => {
inputs.push({
label: i18n.__("Dynamic Redirect", "responsefsf"),
value: "responsefsf_dynamic_redirect",
subOptionLabel: i18n.__("Dynamic Redirect", "responsefsf"),
subOptions: [
{
label: i18n.__("Current Embedded Page", "responsefsf"),
value: "responsefsf_dynamic_redirect"
}
]
});
return inputs;
}
);
});
JS);
});
/**
* 2. Enqueue front-end redirect handler
*/
add_action('wp_enqueue_scripts', function () {
wp_register_script(
'responsefsf-dynamic-redirect',
'',
[],
'1.0.0',
true
);
wp_enqueue_script('responsefsf-dynamic-redirect');
wp_add_inline_script(
'responsefsf-dynamic-redirect',
<<<JS
(function () {
function resolveToken(template, ctx) {
return template.replace(/\\{\\{([^}]+)\\}\\}/g, function (_, token) {
token = token.trim();
if (token === 'current_page') return ctx.url.toString();
if (token === 'current_path') return ctx.url.pathname;
if (token === 'referrer') return document.referrer || '';
return '';
});
}
function buildRedirectUrl(form) {
const u = new URL(window.location.href);
const clean = u.origin + u.pathname;
return new URL(clean);
}
document.addEventListener('srfm_on_show_success_message', function (event) {
const detail = event.detail || {};
const form = detail.form;
if (!form) return;
const submitType = detail.submitType;
const fallback = form.getAttribute('data-responsefsf-confirmation');
if (submitType !== 'responsefsf_dynamic_redirect' &&
fallback !== 'responsefsf_dynamic_redirect') {
return;
}
// Stop SureForms default success behavior
event.preventDefault();
const redirectUrl = buildRedirectUrl(form);
window.location.assign(redirectUrl.toString());
});
})();
JS
);
});PHP