fix(07-01): use DOM monitoring for registration redirect
- Changed from event listener to MutationObserver - Watches for success message text to appear in form - Monitors form DOM for changes and redirects when success appears - More reliable than waiting for custom events
This commit is contained in:
@@ -274,25 +274,57 @@ class DDHH_JM_Formidable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$form_id = self::get_registration_form_id();
|
|
||||||
$redirect_url = home_url( '/anbieter-dashboard/' );
|
$redirect_url = home_url( '/anbieter-dashboard/' );
|
||||||
|
|
||||||
if ( ! $form_id ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
jQuery(document).ready(function($) {
|
jQuery(document).ready(function($) {
|
||||||
// Listen for Formidable form submission success
|
// Watch for Formidable success messages
|
||||||
$(document).on('frmFormComplete', function(event, form, response) {
|
// The form shows "Registrierung erfolgreich! Sie werden weitergeleitet..."
|
||||||
// Check if this is the registration form
|
setInterval(function() {
|
||||||
if (form.attr('id') === 'form_provider_registration' ||
|
// Look for the success message in the form container
|
||||||
form.find('input[name="form_id"]').val() == '<?php echo esc_js( $form_id ); ?>') {
|
var successMsg = $('.frm_message, .frm-message, [class*="success"]').filter(function() {
|
||||||
// Redirect after a short delay to show success message
|
return $(this).text().indexOf('Registrierung erfolgreich') !== -1 ||
|
||||||
|
$(this).text().indexOf('erfolgreich') !== -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (successMsg.length > 0 && successMsg.is(':visible')) {
|
||||||
|
console.log('Success message detected, redirecting...');
|
||||||
|
// Redirect after showing the message
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
window.location.href = '<?php echo esc_js( $redirect_url ); ?>';
|
window.location.href = '<?php echo esc_js( $redirect_url ); ?>';
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
// Stop checking
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
// 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>
|
||||||
|
|||||||
Reference in New Issue
Block a user