Ready to get started?Download WordPress


Adding Custom Shortcode to ContactForm 7 with required filed option (1 post)

  1. salihkulangara
    Posted 9 months ago #

    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>";
    $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.


You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 9 months ago by salihkulangara
  • This topic is not resolved
  • WordPress version: 3.9.1