WordPress.org

Support

Support » Plugins and Hacks » Adding Custom Shortcode to ContactForm 7 with required filed option

Adding Custom Shortcode to ContactForm 7 with required filed option

  • salihkulangara
    Member

    @salihkulangara

    I am trying to use a custom short code in CF7 that I got from WordPress forum, the code works fine as intended, but What I want is the field populated by custom shortcode should be a required field, as we are doing with other fields if I add an asterisk(*) after shortcode it wont work, shortcode will display as a plain text in front-end, If anybody can help me with this.

    I got the code from this Froum Post and code by Wzshop

    and the code is like this

    wpcf7_add_shortcode('postdropdown', 'createbox', true);
    function createbox(){
    global $post;
    $args = array( 'category' => 5 );
    $myposts = get_posts( $args );
    $output = "<select name='cursus' id='cursus' onchange='document.getElementById(\"cursus\").value=this.value;'><option></option>";
    foreach ( $myposts as $post ) : setup_postdata($post);
    	$title = get_the_title();
    	$output .= "<option value='$title'> $title </option>";
    
    	endforeach;
    $output .= "</select>";
    return $output;
    }

    I am using this shortcode – [postdropdown cursus], but i cant use it like this [postdropdown* cursus]

    Can anybody help with this, or else can any one suggest any other option to get data directly from wp database to CF7 field.

  • The topic ‘Adding Custom Shortcode to ContactForm 7 with required filed option’ is closed to new replies.