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.
Parameters Parameters
- $options
-
(array) (Required) Prepared options array.
- $selected_val
-
(mixed) (Required) The value of the option that should be marked as "selected".
Return Return
(string)
Source Source
File: includes/forms/class-llms-form-field.php
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;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 5.0.0 | Introduced. |