• Hi. I have a site that uses multiple WPCF7 forms, which are producing W3C errors because of the multiple ID’s used on reCAPTCHA.

    I’ve been able to retrieve the forms, using AJAX and a bit of logic, but the reCAPTCHA box does not display.

    Any ideas why this might be?

    Here is my code.

    //// WP Template

    <button id="multiForm">Get Form</button>
    <button id="otherForm">Get Other Form</button>

    ///// JS

    jQuery("button").click(function(){
    
    var id = '<?php echo $post->ID; ?>';
    var type = jQuery(this).attr("id");
    
    jQuery.ajax({
    url: ajaxurl + '?action=contactForm&id=' + id + '&type=' + type,
    success: function (data) {
    
    document.getElementById("form").innerHTML = data;
    
    }
    });
    })

    //// Functions.php

    add_action('wp_ajax_nopriv_contactForm','contactForm');
    add_action('wp_ajax_contactForm','contactForm');
    
    function contactForm(){
    
    // Get form
    
    $id = $_REQUEST["id"];
    $type = $_REQUEST["type"];
    
    if($type == 'multiForm') {
    
    $post_object = get_field('contact_form', $id); if( $post_object ): 
    
    $post = $post_object;
    setup_postdata( $post ); 
    
    echo "<h2>";
    echo get_the_title($post);
    echo "</h2>";
    
    echo do_shortcode('[contact-form-7 id="' . $post . '"]');
    
    wp_reset_postdata(); endif;
    
    } else {
    
    echo "Some other form";
    
    }
    
    die();
    
    }

    https://www.ads-software.com/plugins/contact-form-7/

  • The topic ‘WPCF7 reCAPTCHA ID/ACF – PostOjbect’ is closed to new replies.