• Resolved Sabina

    (@pessimisticoptimist)


    Hello,

    I’ve set up a dynamic dropdown that’s using the filter snippet in my functions.php file for the selection options. Is there a way to include headers/labels above some of the selections? Basically I’m trying to recreate the optgroup label function of the select form tag, and would like to have three distinct groups of selections within this one dropdown. I’m not well versed in PHP so struggling a little to know if that’s even possible. I tried using echo to insert the heading text above one of the options, but it ended up bumping that text above the selection box.

    I included a screenshot on the page with my test form of what I’m trying to get the form to look like– I’m trying to insert the gray headers.

    My filter snippet is as follows:

    add_filter(‘cf7sg_dynamic_dropdown_custom_options’, ‘filter_options’,10,3);
    function filter_options($options, $field_name, $form_key){
    if($form_key != ‘test-form’) return $options; //check this is the correct form.
    if($field_name != ‘dynamic_select-863’) return $options; //check this is the correct field.
    $options = array();
    //load your options programmatically, as $value=>$name pairs.
    $options[‘blank’]=’- Select a Bond Type -‘;
    $options[‘bid-bond’]=’Bid Bond (to bid on a new job)’;
    $options[‘performance-pmt’]=’Performance & Payment Bond (for an awarded contract)’;
    $options[‘maintenance’]=’Stand Alone Maintenance Bond (for a warranty)’;
    $options[‘supply-bond’]=’Supply Bond (for a supplier)’;
    return $options;
    }

    So for example, I’d like to enter “Construction & Service Contracts” beneath “Select a Bond Type”, and then have another heading in between the last two options. (I know I don’t have the blank default set up correctly, that will be next on my list if I figure this out.)

    Thanks very much.

    • This topic was modified 5 years, 2 months ago by Sabina.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Sabina

    (@pessimisticoptimist)

    Please disregard this post. I was able to find a commercially available plugin called Quform that has the optgroup functionality I need.

    Noting it here in case anyone else looking for optgroup form ability comes across this post.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    I’m trying to recreate the optgroup label function of the select form tag, and would like to have three distinct groups of selections within this one dropdown.

    no currently this is not possible, but that’s somthing planned for a future release.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Labels/Headers in between Dynamic Dropdown items?’ is closed to new replies.