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,27 +274,59 @@ class DDHH_JM_Formidable {
|
||||
return;
|
||||
}
|
||||
|
||||
$form_id = self::get_registration_form_id();
|
||||
$redirect_url = home_url( '/anbieter-dashboard/' );
|
||||
|
||||
if ( ! $form_id ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function($) {
|
||||
// Listen for Formidable form submission success
|
||||
$(document).on('frmFormComplete', function(event, form, response) {
|
||||
// Check if this is the registration form
|
||||
if (form.attr('id') === 'form_provider_registration' ||
|
||||
form.find('input[name="form_id"]').val() == '<?php echo esc_js( $form_id ); ?>') {
|
||||
// Redirect after a short delay to show success message
|
||||
// Watch for Formidable success messages
|
||||
// The form shows "Registrierung erfolgreich! Sie werden weitergeleitet..."
|
||||
setInterval(function() {
|
||||
// Look for the success message in the form container
|
||||
var successMsg = $('.frm_message, .frm-message, [class*="success"]').filter(function() {
|
||||
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() {
|
||||
window.location.href = '<?php echo esc_js( $redirect_url ); ?>';
|
||||
}, 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>
|
||||
<?php
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user