• Resolved db03

    (@db03)


    Hi, I’m trying to prefill a large set of checkboxes with values from the user meta. The user meta value is an array, but when I use the following shortcode

    default:CF7_get_current_user%20key%3D%26%2339%3Bcategories_de_produits%26%2339%3B

    It seems to return only the first value of the array because only one checkbox is selected.

    Is this happening because the return of the function is actually a string and thus cannot handle an array of values?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter db03

    (@db03)

    I was continuing my research and it looks like a could make my custom shortcode to get the data I need. Where can i write the code so its safe from future updates?

    Thread Starter db03

    (@db03)

    The issue I’m facing is that I can’t set more than one default option. The CF7 documentation suggests that I should be able to specify multiple defaults by separating them with underscores, but this doesn’t seem to work with dynamic checkboxes.

    I’d appreciate any help or suggestions on how to resolve this. Thank you.

    Plugin Author Tessa (they/them), AuRise Creative

    (@tessawatkinsllc)

    Where can i write the code so its safe from future updates?

    See this support thread for options on where to put custom code safely so it doesn’t get overwritten when the plugin is updated.

    Hi, I’m trying to prefill a large set of checkboxes with values from the user meta. The user meta value is an array, but when I use the following shortcode

    default:CF7_get_current_user%20key%3D%26%2339%3Bcategories_de_produits%26%2339%3B

    It seems to return only the first value of the array because only one checkbox is selected.

    Is this happening because the return of the function is actually a string and thus cannot handle an array of values?

    Your assumption is correct, and this is likely an edit I should make since it makes sense that multiple checkboxes could all be checked. I’m about to be very busy this weekend so if you need this implementation sooner than I can fix it, it’s probably best to write a custom shortcode.

    You’re welcome to use wpcf7dtx_checkbox_group_html() and/or wpcf7dtx_checkbox_html() functions as helpers found in the plugin’s utilities.php file.

    Plugin Author Tessa (they/them), AuRise Creative

    (@tessawatkinsllc)

    Specifically, this documentation with example snippets should help you write that custom shortcode, and then compare values using array_intersect() to determine which ones need to be checked/unchecked.

    Thread Starter db03

    (@db03)

    Thank you very much for your response!

    I understand you are busy. Would it be too optimistic to expect a resolution sometime next week? I have plenty to work on in the meantime, especially since I am fairly new to WordPress programming.

    Thank you in advance.

    Plugin Author Tessa (they/them), AuRise Creative

    (@tessawatkinsllc)

    Possibly! I don’t want to make any promises because I’m currently out of town

    Plugin Author Tessa (they/them), AuRise Creative

    (@tessawatkinsllc)

    I was able to squeeze this in version 4.3.1 so using the default attribute with dynamic_checkbox is now consistent with Contact Form 7, meaning listing out the pre-checked values separated by an underscore should do the trick. I don’t know how your categories_de_produits key formats the data, so you might need to use a custom shortcode or the shortcode filter to format the array into an underscore-delimited list.

    Using the filter, it could be something like…

    /**
     * Custom DTX Shortcode Modification
     *
     * @param string $value The sanitized & escaped value that is being outputted by DTX, possibly obfuscated depending on settings.
     * @param mixed $raw_value The raw value retrieved by the built-in shortcode, or the default value depending on settings.
     * @param string $tag Shortcode tag that was used, without the "CF7_" prefix
     * @param array $atts Associative array of the entire shortcode's attributes, combined and filtered with user input.
     *
     * @return string the modified value
     */
    function custom_dtx_shortcode($value, $raw_value, $tag, $atts)
    {
        if(is_array($raw_value)) {
            return apply_filters('wpcf7dtx_escape',  implode('_', $raw_value), $atts['obfuscate']);
        }
        return $value;
    }
    add_filter('wpcf7dtx_shortcode', 'custom_dtx_shortcode', 10, 4);
    masterbip

    (@masterbip)

    Simply amazing. Many Thanks @tessawatkinsllc

    Thread Starter db03

    (@db03)

    YES! thank you very much for your support

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Help! dynamic_checkbox and default values’ is closed to new replies.