• Resolved marbs

    (@marbs)


    Hello,

    I am experiencing issues with the Conditional Fields for Contact Form 7 plugin on my AJAX-powered website. Despite following the provided documentation and various troubleshooting steps, the conditional fields are not reinitializing correctly after an AJAX call.

    After an AJAX call, the conditional logic for my forms does not work as expected. I have ensured that all required scripts are loaded and have followed the instructions from the documentation.

    Steps Taken:

    1. Ensured jQuery is Loaded:

    function my_enqueue_scripts() {
    wp_enqueue_script('jquery');
    }
    add_action('wp_enqueue_scripts', 'my_enqueue_scripts');

    2. Added Initialization Script:

    function initializeConditionalFields() {
    if (typeof wpcf7 !== 'undefined' && typeof wpcf7cf !== 'undefined') {
    const $form = jQuery('.wpcf7-form').eq(0);
    wpcf7.init($form[0]);
    wpcf7cf.initForm($form);
    }
    }

    jQuery(document).ready(function() {
    initializeConditionalFields();
    });

    jQuery(document).ajaxComplete(function() {
    initializeConditionalFields();
    });

    Ensured no syntax errors in custom scripts or functions.php.

    Verified Theme Calls wp_footer():

    Despite these steps, the conditional fields are not working correctly after an AJAX call.

    Thank you for your support!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Issues Initializing Conditional Logic After AJAX Calls’ is closed to new replies.