• Resolved Noshad Ali

    (@noshad19)


    I have a contact form with a dropdown. I cannot change the default placeholder for the dropdown. It is fixed to —Please choose an option —-

    How do I change it to whatever I want?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    See Drop-down menus

    Use the first_as_label option instead of include_blank.

    You can add filter hook for changing default text ” —Please choose an option—” .

    $html = str_replace(‘—Please choose an option—’, $text, $html);
    function my_wpcf7_form_elements($html) {
        //wp_send_json($html );
        $text = 'Select Option';
        $html = str_replace('—Please choose an option—',  $text, $html);
    
        return $html;
    }
    add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
    • This reply was modified 1 year, 4 months ago by MH Sohag.
    • This reply was modified 1 year, 4 months ago by MH Sohag.

    @mhsohag11 Thank you. Didn’t work for me i had to change – with & #8212;

    • This reply was modified 1 year, 4 months ago by classikd.
    • This reply was modified 1 year, 4 months ago by classikd.
    • This reply was modified 1 year, 4 months ago by classikd.

    Hi. Where do I have to insert this filter? In which page?

    Replacing the include_blank with first_as_label works great, thanks!

    1- Replacing the include_blank with first_as_label 
    2- use this script to disable first option

    (function ($) {
       'use strict';
       $(document).ready(function () {
           var $select = $('.wpcf7-select');
           $select.each(function(e){
             var first_option = $(this).find('option').first();
             if(first_option.attr('value') == ''){
               first_option.attr('disabled', true);
             }
         })
      });
    })(jQuery)
    • This reply was modified 1 year, 1 month ago by mkkmail.
    • This reply was modified 1 year, 1 month ago by mkkmail.
    mandipluitel

    (@mandipluitel)

    function wpcf7_select_placeholder_update($html) {
        $text = 'How did you hear about us?';
        $html = str_replace('<option value="">—Please choose an option—</option>', '<option value="">' . $text . '</option>', $html);
        return $html;
    }
    add_filter('wpcf7_form_elements', 'wpcf7_select_placeholder_update');

    Try this and also as mentioned above use (&@8212 ; ) instead of –

    hoggologh

    (@hoggologh)

    keep it simple

    2- use this script to disable first option

    <script>
    $(function() {
    $('.wpcf7-select option:first-child[value=""]').prop('disabled', true);
    });
    </script>

    For those, who tried suggestions by mandipluitel and by MH Sohag, but they have not worked:

    When posting a comment, editor script forcefully converts &# 8212; into em dash, but with those dashes code by mandipluitel and by MH Sohag does not work, being otherwise right. Since in the code generated by Contact form 7 text to replace looks like: “&# 8212;Please choose an option&# 8212;”, not with dashes.

    Note: I put &# + blank space + 8212 to avoid conversion to em dash, so that blank space should be remove in the actual code.

    • This reply was modified 11 months, 3 weeks ago by bonmot.
    • This reply was modified 11 months, 3 weeks ago by bonmot.
    • This reply was modified 11 months, 3 weeks ago by bonmot.
    • This reply was modified 11 months, 3 weeks ago by bonmot.
    • This reply was modified 11 months, 3 weeks ago by bonmot.
    • This reply was modified 11 months, 3 weeks ago by bonmot.
    • This reply was modified 11 months, 3 weeks ago by bonmot.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Contact Form 7 Dropdown Place Holder’ is closed to new replies.