Contact Form 7 option by default to print as selected value by mail
[select my_select class:input class:styled "Select Options"
"Option 1" "Option 2" "Option 3" "Option 4"]
Question:
How can I prevent printing 'Select Options'
if the user has not selected any options when receiving email? If the user chooses the first option ('Select Options')
, he does not have to print like 'Select Options'
mail.
source to share
[select my_select first_as_label class:styled "Select Options" "Option 1" "Option 2" "Option 3" "Option 4"]
Alternatively, you can check the documentation .
Change your select tag to
[select my_select class:input class:styled include_blank "Option 1" "Option 2" "Option 3" "Option 4"]
The first option will have "---" as text and empty value, <option value="">---</option>
If you want to replace the text "---" with "Select parameters", add the following code to functions.php
function my_wpcf7_form_elements($html) {
$text = 'Select Option';
$html = str_replace('---', $text , $html);
return $html;
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
source to share
These solutions worked exactly as I wanted. so all forms have consistency and the same default selected - you need to add "include_blank" to the field shortcode:
/**
* Customize the default option selected on CF7
*/
function my_wpcf7_form_elements($html) {
$text = '—';
$html = str_replace('---', $text , $html);
return $html;
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
As https://stackoverflow.com/users/80368/anand-shah commented
source to share