LLMS_Form_Field::get_option_list_html( array $options, mixed $selected_val )

Retrieve the HTML for an options list in a select field.


Description Description

This function works recursively to build optgroups.


Top ↑

Parameters Parameters

$options

(array) (Required) Prepared options array.

$selected_val

(mixed) (Required) The value of the option that should be marked as "selected".


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/forms/class-llms-form-field.php

544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
protected function get_option_list_html( $options, $selected_val ) {
 
    $html = '';
    foreach ( $options as $key => $val ) {
 
        if ( is_array( $val ) ) {
 
            $label         = isset( $val['label'] ) ? $val['label'] : $key;
            $group_options = isset( $val['options'] ) ? $val['options'] : $val;
            $html         .= sprintf( '<optgroup label="%1$s" data-key="%2$s">%3$s</optgroup>', esc_attr( $label ), esc_attr( $key ), $this->get_option_list_html( $group_options, $selected_val ) );
 
        } else {
 
            $selected = ( (string) $key === (string) $selected_val ) ? ' selected="selected"' : '';
            $disabled = ( $this->settings['placeholder'] && '' === $key ) ? ' disabled="disabled"' : '';
            $html    .= sprintf( '<option value="%1$s"%3$s%4$s>%2$s</option>', esc_attr( $key ), esc_attr( $val ), $selected, $disabled );
 
        }
    }
 
    return $html;
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.