• Resolved Nokaa

    (@nokaa)


    Hi,

    I’ve come here because I fail to set a default ‘option’ for a select input in my form. I want to make it pass by the shortcode so my writers could choose the default option depending on the subject of the article. So I tried this method : https://contactform7.com/getting-default-values-from-shortcode-attributes/
    But it doesn’t work.

    There is what I’ve done :

    In the form edition :
    [select* services default:shortcode_attr class:cf-dp-services "Wireless Alarms|A02" "Security Phone|S03" "Locks|S08" "Remote Monitoring|R08"]

    In the shortcode on an article about Remote Monitoring :
    [contact-form-7 id="5488" title="Article Form" services="Remote Monitoring|R08"]

    The entiere functions.php of my child theme :

    <?php
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'parent-style-shortcodes', get_template_directory_uri() . '/css/shortcodes.css' );
        wp_enqueue_style( 'parent-style-prettyphoto', get_template_directory_uri() . '/css/prettyPhoto.css' );
        wp_enqueue_style( 'parent-style-woocustom', get_template_directory_uri() . '/css/woo-custom.css' );	
        wp_enqueue_style( 'parent-style-responsive', get_template_directory_uri() . '/css/responsive.css' );	
    }
    
    add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 );
    
    function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
        $attr_se = 'services';
    	
        if ( isset( $atts[$attr_se] ) ) {
            $out[$attr_se] = $atts[$attr_se];
        }
     
        return $out;
    }
    
    ?>

    But the forms keep the first choice (Alarms) as default option of the select input…

    What did I wrong ?

    Thank you in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Change the shortcode to:

    [contact-form-7 id="5488" title="Article Form" services="Remote Monitoring"]

    You don’t need the part after pipe here.

    Thread Starter Nokaa

    (@nokaa)

    Thank you for the fast answer, it seems to work ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Default option of a select input from shortcode ?’ is closed to new replies.