Support » Plugin: cformsII » optgroup in select

  • Resolved Sonika



    I need to make optgroup in select in form, and i found the decision, it seems everything is correct but it doesn’t work:


    In header.php:

    <script type="text/javascript">
      $(".cform select option").each(function(){
        if($(this).val() == "groupstart"){
          var label = $(this).text();
            .wrapAll("<optgroup label='"+label+"' />");

    Once you have that code in place, all you need to do is add groupstart and groupend codes to your cforms settings for your select box. For the groupstart you will add it as though it were just another option, with the label being the label you want for your group, and the value being the literal string “groupstart.” For the groupend, it doesn’t matter what the label is, as long as the value is “groupend.” It’s easiest just to use groupend as the label, and leaving the value empty so that CForms will automatically use the label as the value.

    and in form:
    Color#Choose#Warm Colors|groupstart#red#orange#yellow#|groupend#Cool Colors|groupstart#blue#green#purple#|groupend#brown#black#white

    It should be like this:

    But i get this:


    • This topic was modified 9 months, 4 weeks ago by  Sonika.
    • This topic was modified 9 months, 4 weeks ago by  Sonika.
Viewing 1 replies (of 1 total)
  • If anyone is interested, I found 1 solution, a bit silly but it works and for me it is enough 🙂


    //Replace anything anywhere in the page output
    if ( !is_admin() ) {
        function vr51_callback($buffer) {
            $find = array(
            '<option value="groupstart">ONE</option>', 
            '<option value="groupstart"TWO</option>', 
            '<option value="groupstart">33333</option>',
            '<option value="groupstart">44444</option>',
            '<option value="groupend"></option>'
            $replace  = array(
            '<optgroup label="ONE">', 
            '<optgroup label="TWO">', 
            '<optgroup label="33333">',
            '<optgroup label="44444">',
            $buffer = str_replace($find, $replace, $buffer);
            return $buffer;
        add_action('wp_loaded', 'buffer_start');    function buffer_start() { ob_start("vr51_callback"); }
        add_action('shutdown', 'buffer_end');       function buffer_end()   { ob_end_flush(); }
    //********************* END Replace anything anywhere in the page output 
    • This reply was modified 9 months, 3 weeks ago by  Sonika.
Viewing 1 replies (of 1 total)
  • The topic ‘optgroup in select’ is closed to new replies.