I have this code for my custom field:

add_action( 'wpcf7_init', 'custom_views_post_title' );
function custom_views_post_title() {
wpcf7_add_shortcode( 'custom_views_post_title', 'custom_views_post_title_shortcode_handler' );}
function custom_views_post_title_shortcode_handler( $tag ) {
global $post;
$args = array( 'post_type' => 'post' );
$myposts = get_posts( $args );
$output = '<span class="wpcf7-form-control-wrap"><select name="lstdate" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required" id="fleet" onchange="document.getElementById(\'fleet\').value=this.value;" aria-required="true" aria-invalid="false"><option value="" disabled selected>Select something</option>';
foreach ( $myposts as $post ) : setup_postdata($post);
   $title = get_the_title();
   $output .= '<option value="'. $title .'">'. $title .' </option>';

$output .= "</select></span>";
return $output; }

How can I make this field required and validate it?

Thanks a lot!

  • Is there nobody who can answer that? – Luke Feb 6 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.