keep the drop down unselected.
-
Hi we are using dynamic select to list post titles in a dropdown. But since it is required field and already selected. How can we add a placeholder or an empty choice, so that there’s nothing selected in it.
Here’s the function code:
function cf7_dynamic_select() {
$args = array ( ‘post_type’ => ‘post’,
‘numberposts’ => 5000,
‘category’=> 85,
‘orderby’ => ‘title’,
‘order’ => ‘ASC’ );
$label=” “;
$value=”None”;
$option[$label] = $value;
$posts = get_posts($args);
foreach ( $posts as $post ) {
$label = $post->post_title; // label of menu select option
$value = $post->post_title; // value of menu select option
$options[$label] = $value;
}
return $options;
}
add_filter(‘Intl-programs’, ‘cf7_dynamic_select’, 10, 2);Form tag:
<div class=”column-half”>Program Interested*[dynamicselect* Program “Intl-programs”]</div>I hope I might be able to explain. We want nothing selected by default. but it selects the top value of the dropdown. how can we place an empty choice? so that the user have to drop down and select one of the choices.
- The topic ‘keep the drop down unselected.’ is closed to new replies.