Skip to content

Commit 1a91916

Browse files
committed
fix(embed): honor redirect URL after submit + keep the success message themed
- The `redirectUrl` setting was never applied — on submit the embed now redirects to it (window.location.href) when set, otherwise shows the success message. - The success message was appended after the themed <form> was cleared, losing the theme. It's now wrapped in .sfb-form with the resolved --sfb-* vars re-applied, so it stays styled (notably on third-party embeds where there's no card to inherit from). Small padding tweak on .sfb-success. Verified end-to-end: a cross-origin embed auto-submits and navigates to the redirect.
1 parent 9d3c2d9 commit 1a91916

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

admin/src/form-css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ select.sfb-input { appearance: none; cursor: pointer; }
2929
.sfb-heading { font-size: 18px; font-weight: 700; color: var(--sfb-text, #1f1f33); margin: 4px 0; }
3030
.sfb-paragraph { font-size: 14px; color: var(--sfb-muted, #666687); margin: 4px 0; line-height: 1.6; }
3131
.sfb-divider { border: none; border-top: 1px solid var(--sfb-border, #dcdce4); margin: 4px 0; }
32-
.sfb-success { font-size: 15px; color: #27ae60; font-weight: 600; }
32+
.sfb-success { font-size: 16px; color: #27ae60; font-weight: 600; padding: 8px 0; margin: 0; }
3333
.sfb-error { font-size: 13px; color: #ee5e52; margin-bottom: 12px; }
3434
.sfb-field-error { font-size: 12px; color: #ee5e52; margin: 4px 0 0; }
3535
.sfb-field--error .sfb-input, .sfb-field--error .sfb-radio-group { border-color: #ee5e52 !important; }

server/src/controllers/form.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,23 @@ function embedScript(): string {
225225
});
226226
})
227227
.then(function () {
228+
// redirect after submit, if configured
229+
var redirect = form.settings && form.settings.redirectUrl;
230+
if (redirect) { window.location.href = redirect; return; }
231+
// otherwise show the success message — wrapped in .sfb-form + re-applying the
232+
// theme so it stays styled (the themed <form> we just cleared is gone)
233+
var wrap = document.createElement('div');
234+
wrap.className = 'sfb-form';
235+
if (form.settings && form.settings.themeVars) {
236+
var stv = form.settings.themeVars;
237+
for (var sk in stv) { if (Object.prototype.hasOwnProperty.call(stv, sk)) wrap.style.setProperty(sk, stv[sk]); }
238+
}
228239
var msg = document.createElement('p');
229240
msg.className = 'sfb-success';
230241
msg.textContent = (form.settings && form.settings.successMessage) || 'Form submitted successfully';
242+
wrap.appendChild(msg);
231243
el.innerHTML = '';
232-
el.appendChild(msg);
244+
el.appendChild(wrap);
233245
})
234246
.catch(function (body) {
235247
btn.disabled = false;

0 commit comments

Comments
 (0)