• Resolved PaulShipley

    (@paulshipley)


    Hi!

    This is not a support question, but a code suggestion and tip for anyone else with this issue.

    I’m using Contact Form 7 – Dynamic Text Extension (v4.4.2) and have a shortcode to generate the Radio button HTML which contains an img tag, however the image was not showing as the tag was being removed.

    Code snippet:

        while ($loop->have_posts()) : $loop->the_post();
            $product_id = $loop->post->ID;
            $product = wc_get_product($product_id);
            $radio_html = $radio_html . '<input type="radio" id="product_' . $product_id . '" dtx-default="" ' .
                'class="wpcf7-form-control wpcf7-radio wpcf7dtx wpcf7dtx-radio" aria-invalid="false" ' .
                'name="' . $badge_group . '" value="' . $product_id . '" required="required" ' . $checked .
                '/><label for="product_' . $product_id . '">' .
                wp_get_attachment_image($product->get_image_id(), "medium") . '</label>';
            $checked = '';
        endwhile;

    Expected:

    <span class="wpcf7-form-control-wrap my_badges" data-name="my_badges">
    <input type="radio" id="product_3263" dtx-default="" class="wpcf7-form-control wpcf7-radio wpcf7dtx wpcf7dtx-radio" aria-invalid="false" name="my_badges" value="3263" required="required" checked="1">
    <label for="product_3263">
    <img decoding="async" src="https://example.com/wp-content/uploads/2020/11/Image-300x114.jpg"/>
    </label>
    </span>

    Actual:

    <span class="wpcf7-form-control-wrap my_badges" data-name="my_badges">
    <input type="radio" id="product_3263" dtx-default="" class="wpcf7-form-control wpcf7-radio wpcf7dtx wpcf7dtx-radio" aria-invalid="false" name="my_badges" value="3263" required="required" checked="1">
    <label for="product_3263">
    </label>
    </span>

    I found that the issue was in the wpcf7dtx_shortcode_handler function that sanitizes the HTML tags and wasn’t on the list for type=radio, so I added it.

    contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension.php

    Line 519-523:

            ), array_merge($allowed_html, array(
                'label' => array('for' => array()),
    
                // vvv my change
                'img' => array('src' => array()),
                // ^^^
    
                'input' => wpcf7dtx_get_allowed_field_properties($atts['type'])
            )));

    HTH

Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.