• I am facing a issue that i can’t able to add placeholder in dropdown. Which cannot be selected by anyone.
    I have tried first_as_label but anyone can select it.
    The thing i need is just simple:
    <select name=”tagging”>
    <option value=”” disabled=”disabled”>–state–</option>
    <option value=”Option A”>Option A</option>
    <option value=”Option B”>Option B</option>
    <option value=”Option C”>Option C</option>
    </select>

Viewing 2 replies - 1 through 2 (of 2 total)
  • I am looking for this too. I found someone reference the CF7 website and say it was listed there that placeholders were possible, but I navigate to the link and search to find nothing… Disappointed. You would think if you select the “Insert a blank item as the first option” field and then use placeholder… It could write it out disabling the first item as in above. Or at a minimum ADD a disable first option field in the generator.

    • This reply was modified 7 years, 10 months ago by leaninonlife.

    Found this today:

    // Modify multiple selects - Target each one specifically
    function my_wpcf7_form_elements($html) {
    	function ov3rfly_replace_include_blank($name, $text, &$html) {
    		$matches = false;
    		preg_match('/<select name="' . $name . '"[^>]*>(.*)<\/select>/iU', $html, $matches);
    		if ($matches) {
    			$select = str_replace('<option value="">---</option>', '<option value="">' . $text . '</option>', $matches[0]);
    			$html = preg_replace('/<select name="' . $name . '"[^>]*>(.*)<\/select>/iU', $select, $html);
    		}
    		add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
    	}
    	ov3rfly_replace_include_blank('menu-29', '--Select--', $html);
    	// ov3rfly_replace_include_blank('menu-614', 'Choose country', $html);
            // ov3rfly_replace_include_blank('menu-2', 'Some other', $html);
    	// ov3rfly_replace_include_blank('menu-64', 'Choose country', $html);
            // ov3rfly_replace_include_blank('menu-9', 'Some Some Other', $html);
    	// ov3rfly_replace_include_blank('menu-14', 'Choose country', $html);
    	return $html;
    }
    add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add placeholder in contact form 7 dropdown select box’ is closed to new replies.