← All changes
|
includes/Frontend/Form/View/Conversational/Fields/HtmlSelectField.php
+12
-5
3.1.3
→
V3.3.2
View file →
| @@ -19,9 +19,9 @@ | ||
| 19 | 19 | if (isset($opt->val) && $opt->val === $val) { |
| 20 | 20 | $selected = 'selected'; |
| 21 | 21 | } elseif (isset($opt->lbl) && $opt->lbl === $val) { |
| 22 | 22 | $selected = 'selected'; |
| 23 | - } elseif (property_exists($opt, 'check')) { | |
| 23 | + } elseif (is_object($opt) && property_exists($opt, 'check')) { | |
| 24 | 24 | $selected = 'selected'; |
| 25 | 25 | } |
| 26 | 26 | return $selected; |
| 27 | 27 | } |
| @@ -60,10 +60,13 @@ | ||
| 60 | 60 | $fieldHelpers->kses_post($field->ph) |
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if (property_exists($field, 'opt')) { | |
| 64 | + if (property_exists($field, 'opt') && is_iterable($field->opt)) { | |
| 65 | 65 | foreach ($field->opt as $opt) { |
| 66 | + if (!is_object($opt)) { | |
| 67 | + continue; | |
| 68 | + } | |
| 66 | 69 | $disabled = property_exists($opt, 'disabled') ? 'disabled' : ''; |
| 67 | 70 | if (property_exists($opt, 'type')) { |
| 68 | 71 | $optionsHTML .= sprintf( |
| 69 | 72 | '<optgroup |
| @@ -76,10 +79,14 @@ | ||
| 76 | 79 | $fieldHelpers->getConversationalCls('slct-opt-grp') . ' ' . $fieldHelpers->getCustomClasses('slct-opt-grp'), |
| 77 | 80 | $fieldHelpers->esc_attr($opt->title), |
| 78 | 81 | $disabled |
| 79 | 82 | ); |
| 80 | - foreach ($opt->childs as $child) { | |
| 81 | - $val = isset($child->val) ? $child->val : $child->lbl; | |
| 83 | + $optChilds = isset($opt->childs) && is_iterable($opt->childs) ? $opt->childs : []; | |
| 84 | + foreach ($optChilds as $child) { | |
| 85 | + if (!is_object($child)) { | |
| 86 | + continue; | |
| 87 | + } | |
| 88 | + $val = isset($child->val) ? $child->val : ($child->lbl ?? ''); | |
| 82 | 89 | $selected = self::checkSelected($child, $value); |
| 83 | 90 | $disabled = property_exists($child, 'disabled') ? 'disabled' : ''; |
| 84 | 91 | $optionsHTML .= sprintf( |
| 85 | 92 | '<option |
| @@ -101,9 +108,9 @@ | ||
| 101 | 108 | } |
| 102 | 109 | $optionsHTML .= '</optgroup>'; |
| 103 | 110 | } else { |
| 104 | 111 | $selected = self::checkSelected($opt, $value); |
| 105 | - $val = isset($opt->val) ? $opt->val : $opt->lbl; | |
| 112 | + $val = isset($opt->val) ? $opt->val : ($opt->lbl ?? ''); | |
| 106 | 113 | $optionsHTML .= sprintf( |
| 107 | 114 | '<option |
| 108 | 115 | %1$s |
| 109 | 116 | class="%2$s" |