_comment.php
4 months ago
_db.php
4 months ago
_hidden.php
4 months ago
_label.php
4 months ago
_row.php
4 months ago
attachment.php
4 months ago
checkbox.php
4 months ago
cleditor.php
4 months ago
codemirror.php
4 months ago
color.php
4 months ago
currency.php
4 months ago
date.php
4 months ago
datetime.php
4 months ago
email.php
4 months ago
link.php
4 months ago
number.php
4 months ago
oembed.php
4 months ago
password.php
4 months ago
phone.php
4 months ago
radio.php
4 months ago
select.php
4 months ago
slider.php
4 months ago
slug.php
4 months ago
text.php
4 months ago
textarea.php
4 months ago
time.php
4 months ago
tinymce.php
4 months ago
website.php
4 months ago
select.php
113 lines
| 1 | <?php |
| 2 | |
| 3 | // Don't load directly. |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | die( '-1' ); |
| 6 | } |
| 7 | |
| 8 | // phpcs:ignoreFile WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound |
| 9 | |
| 10 | $attributes = array(); |
| 11 | $attributes['tabindex'] = 2; |
| 12 | |
| 13 | $pick_limit = (int) pods_v( $form_field_type . '_limit', $options, 0 ); |
| 14 | $multiple = false; |
| 15 | |
| 16 | if ( 'multi' === pods_v( $form_field_type . '_format_type', $options ) && 1 != $pick_limit ) { |
| 17 | $name .= '[]'; |
| 18 | $attributes['multiple'] = 'multiple'; |
| 19 | $multiple = true; |
| 20 | } |
| 21 | |
| 22 | if ( ! is_array( $options['data'] ) && false !== $options['data'] && 0 < strlen( $options['data'] ) ) { |
| 23 | $options['data'] = implode( ',', $options['data'] ); |
| 24 | } else { |
| 25 | $options['data'] = (array) pods_v( 'data', $options, [] ); |
| 26 | } |
| 27 | |
| 28 | $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options ); |
| 29 | |
| 30 | if ( (bool) pods_v( 'readonly', $options, false ) ) { |
| 31 | $attributes['readonly'] = 'READONLY'; |
| 32 | |
| 33 | $attributes['class'] .= ' pods-form-ui-read-only'; |
| 34 | } |
| 35 | |
| 36 | $selection_made = false; |
| 37 | ?> |
| 38 | <select<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?>> |
| 39 | <?php |
| 40 | foreach ( $options['data'] as $option_value => $option_label ) { |
| 41 | if ( is_array( $option_label ) && isset( $option_label['label'] ) ) { |
| 42 | $option_label = $option_label['label']; |
| 43 | } |
| 44 | |
| 45 | if ( is_array( $option_label ) ) { |
| 46 | ?> |
| 47 | <optgroup label="<?php echo esc_attr( $option_value ); ?>"> |
| 48 | <?php |
| 49 | foreach ( $option_label as $sub_option_value => $sub_option_label ) { |
| 50 | if ( is_array( $sub_option_label ) ) { |
| 51 | if ( isset( $sub_option_label['label'] ) ) { |
| 52 | $sub_option_label = $sub_option_label['label']; |
| 53 | } else { |
| 54 | $sub_option_label = $sub_option_value; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | $sub_option_label = (string) $sub_option_label; |
| 59 | |
| 60 | $is_selected = false; |
| 61 | $options['selected'] = ''; |
| 62 | |
| 63 | if ( ! $selection_made && ( ( ! is_array( $value ) && (string) $sub_option_value === (string) $value ) || ( is_array( $value ) && ( in_array( $sub_option_value, $value ) || in_array( (string) $sub_option_value, $value ) ) ) ) ) { |
| 64 | $is_selected = true; |
| 65 | $options['selected'] = 'selected'; |
| 66 | |
| 67 | if ( ! $multiple ) { |
| 68 | $selection_made = true; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if ( is_array( $sub_option_value ) ) { |
| 73 | ?> |
| 74 | <option<?php PodsForm::attributes( $sub_option_value, $name, $form_field_type . '_option', $options ); ?>><?php echo esc_html( $sub_option_label ); ?></option> |
| 75 | <?php |
| 76 | } else { |
| 77 | ?> |
| 78 | <option value="<?php echo esc_attr( $sub_option_value ); ?>"<?php selected( $is_selected ); ?>><?php echo esc_html( $sub_option_label ); ?></option> |
| 79 | <?php |
| 80 | } |
| 81 | }//end foreach |
| 82 | ?> |
| 83 | </optgroup> |
| 84 | <?php |
| 85 | } else { |
| 86 | $option_label = (string) $option_label; |
| 87 | |
| 88 | $is_selected = false; |
| 89 | $options['selected'] = ''; |
| 90 | |
| 91 | if ( ! $selection_made && ( ( ! is_array( $value ) && (string) $option_value === (string) $value ) || ( is_array( $value ) && ( in_array( $option_value, $value ) || in_array( (string) $option_value, $value ) ) ) ) ) { |
| 92 | $is_selected = true; |
| 93 | $options['selected'] = 'selected'; |
| 94 | |
| 95 | if ( ! $multiple ) { |
| 96 | $selection_made = true; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if ( is_array( $option_value ) ) { |
| 101 | ?> |
| 102 | <option<?php PodsForm::attributes( $option_value, $name, $form_field_type . '_option', $options ); ?>><?php echo esc_html( $option_label ); ?></option> |
| 103 | <?php |
| 104 | } else { |
| 105 | ?> |
| 106 | <option value="<?php echo esc_attr( $option_value ); ?>"<?php selected( $is_selected ); ?>><?php echo esc_html( $option_label ); ?></option> |
| 107 | <?php |
| 108 | } |
| 109 | }//end if |
| 110 | }//end foreach |
| 111 | ?> |
| 112 | </select> |
| 113 |