fix(07-01): prevent multiple redirect triggers causing server crash
- Added ddhhRedirectTriggered flag to ensure only one redirect - Clear interval immediately when success message detected - Removed MutationObserver which was causing duplicate events - Simplified JavaScript to single interval-based check
This commit is contained in:
@@ -278,54 +278,33 @@ class DDHH_JM_Formidable {
|
|||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
jQuery(document).ready(function($) {
|
jQuery(document).ready(function($) {
|
||||||
|
var ddhhRedirectTriggered = false;
|
||||||
|
|
||||||
|
function triggerRedirect() {
|
||||||
|
if (ddhhRedirectTriggered) return;
|
||||||
|
ddhhRedirectTriggered = true;
|
||||||
|
console.log('DDHH: Redirecting to dashboard in 1.5s...');
|
||||||
|
setTimeout(function() {
|
||||||
|
window.location.href = '<?php echo esc_js( $redirect_url ); ?>';
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
|
|
||||||
// Watch for Formidable success messages
|
// Watch for Formidable success messages
|
||||||
// The form shows "Registrierung erfolgreich! Sie werden weitergeleitet..."
|
var checkInterval = setInterval(function() {
|
||||||
setInterval(function() {
|
if (ddhhRedirectTriggered) {
|
||||||
// Look for the success message in the form container
|
clearInterval(checkInterval);
|
||||||
var successMsg = $('.frm_message, .frm-message, [class*="success"]').filter(function() {
|
return;
|
||||||
return $(this).text().indexOf('Registrierung erfolgreich') !== -1 ||
|
}
|
||||||
$(this).text().indexOf('erfolgreich') !== -1;
|
|
||||||
|
var successMsg = $('.frm_message, .frm-message').filter(function() {
|
||||||
|
return $(this).text().indexOf('Registrierung erfolgreich') !== -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (successMsg.length > 0 && successMsg.is(':visible')) {
|
if (successMsg.length > 0 && successMsg.is(':visible')) {
|
||||||
console.log('Success message detected, redirecting...');
|
clearInterval(checkInterval);
|
||||||
// Redirect after showing the message
|
triggerRedirect();
|
||||||
setTimeout(function() {
|
|
||||||
window.location.href = '<?php echo esc_js( $redirect_url ); ?>';
|
|
||||||
}, 1500);
|
|
||||||
// Stop checking
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 200);
|
||||||
|
|
||||||
// Also listen for form submission completion
|
|
||||||
if (typeof window.FrmForm !== 'undefined') {
|
|
||||||
console.log('Formidable Form object found');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: Monitor form elements for changes
|
|
||||||
// Look for any Formidable form that might be the registration form
|
|
||||||
$('form').each(function() {
|
|
||||||
var form = $(this);
|
|
||||||
var formId = form.find('[name="form_id"]').val();
|
|
||||||
console.log('Found form with ID:', formId);
|
|
||||||
|
|
||||||
// Watch for display of success message in this form
|
|
||||||
var observer = new MutationObserver(function(mutations) {
|
|
||||||
mutations.forEach(function(mutation) {
|
|
||||||
var text = $(mutation.target).text();
|
|
||||||
if (text.indexOf('erfolgreich') !== -1 || text.indexOf('Registrierung') !== -1) {
|
|
||||||
console.log('Success message appeared in form', formId);
|
|
||||||
setTimeout(function() {
|
|
||||||
window.location.href = '<?php echo esc_js( $redirect_url ); ?>';
|
|
||||||
}, 1500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Monitor the form for changes
|
|
||||||
observer.observe(form[0], { childList: true, subtree: true, characterData: true });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
Reference in New Issue
Block a user