Custom shortcode with required field Contact Form 7
-
Hey guys,
This is my first post and I’m a bit of a newbie but hope you guys can help. I’ve searched the forum and googled but I can’t seem to find an answer.
I basically added a hook to my functions.php file to support a custom shortcode for Contact Form 7 (which is awesome btw) to go pull posts for a specific category. I got it working but whenever I use the * character to indicate if a field is required it doesn’t work.
Note: I got the code from this http://wordpress.org/support/topic/how-to-add-new-custom-shortcode Post and code by Wzshop.
Code:
add_action( 'wpcf7_init', 'custom_add_shortcode_dropdown' ); function custom_add_shortcode_dropdown() { wpcf7_add_shortcode( array( 'postdropdown', 'postdropdown*'), 'custom_dropdown_shortcode_handler', true); } function custom_dropdown_shortcode_handler(){ global $post; $args = array('category_name' => 'activite-a-venir'); $myposts = get_posts( $args ); $output = "<select name='formation'><option value=\"\">---</option>"; foreach ( $myposts as $post ) : setup_postdata($post); $title = get_the_title(); $output .= "<option value='$title'> $title </option>"; endforeach; $output .= "</select>"; return $output; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Custom shortcode with required field Contact Form 7’ is closed to new replies.