Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contact form 7 default option print as selected value in mail

[select my_select class:input class:styled "Select Options"   
"Option 1" "Option 2" "Option 3" "Option 4"]

Question:

How to prevent printing 'Select Options' if user not selected any options in receiving email? If user select first option ('Select Options'),it should not print as 'Select Options' in mail.

like image 339
Sree Avatar asked Nov 13 '14 05:11

Sree


People also ask

How do I set the default value in Contact Form 7?

To do this, add default:{source} option to the form-tag from which you want to derive the default value. Available data sources are: get (HTTP GET variables), post (HTTP POST variables), and post_meta (custom fields). Logged-in user information is also available.

How do I create a placeholder dropdown in Contact Form 7?

More recent versions of Contact Form 7 allow the use of first_as_label to create placeholder text that does not validate as an entry if users do not make a selection. Simply make your placeholder text be the first label in the list of options. wow. It works.


1 Answers

Change your select tag to the following

[select my_select class:input class:styled include_blank "Option 1" "Option 2" "Option 3" "Option 4"]

The first option will have "---" as the text and a blank value, <option value="">---</option>

If you want to replace the text "---" with "Select Options" 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');
like image 96
Anand Shah Avatar answered Sep 24 '22 19:09

Anand Shah