select pick

main
Robert 1 month ago
parent 0fc6bd6186
commit ee021fd704
  1. 7
      src/bootstrap/safer_io.php
  2. 41
      src/classes/form_builder/html_form.php

@ -545,10 +545,11 @@ final class safer_io {
if (isset($a->input_var)) {
$user_text = $a->input_var;
} elseif (isset($a->input_type) && $a->input_type instanceof \UnitEnum) {
if (empty($alt_name)) {
$user_text = self::get_input_by_type($input_field_name, $a->input_type);
} else {
if (isset($alt_name)) {
$user_text = self::get_input_by_type($alt_name, $a->input_type);
$meta['alt'][$input_field_name] = [$alt_name, $user_text];
} else {
$user_text = self::get_input_by_type($input_field_name, $a->input_type);
}
} else {
$ret['name'] = $input_field_name;

@ -128,12 +128,35 @@ class html_form {
$skip_output = [];
foreach(SafeIO::esv($input['html']) as $html) {
$key = $html['name'] ?? "";
$html_output[$key] = $html['html'];
$alt = $html['meta']['alt'][$key] ?? null;
if (isset($alt)) {
$alt_name = $alt[0] ?? null;
$alt_value = $alt[1] ?? null;
if (isset($alt_name) && isset($alt_value)) {
$html_output[$alt_name] = $alt_value;
} else {
$html_output[$key] = $html['html'];
}
} else {
$html_output[$key] = $html['html'];
}
$headers[$key] = $html['meta']['field_desc'][$key] ?? "";
$skipping = $html['meta']['skip_output'][$key] ?? null;
if ($skipping === true) {
$skip_output[$key] = true;
if (isset($alt_name)) {
$skipping = $html['meta']['skip_output'][$key] ?? null;
if ($skipping === true) {
// skip both alt_name and key
$skip_output[$alt_name] = true;
$skip_output[$key] = true;
}
} else {
$skipping = $html['meta']['skip_output'][$key] ?? null;
if ($skipping === true) {
$skip_output[$key] = true;
}
}
$show_labels = $html['meta']['show_label'][$key] ?? true;
$form_type = $html['meta']['form_type'][$key] ?? FORM_TYPE::text;
$form_data_list = $html['meta']['form_data_list'][$key] ?? [];
@ -360,12 +383,22 @@ class html_form {
$html .= $this->build_options($children, $selected);
$html .= '</optgroup>';
} else {
if ($value === "none") {
$option[] = 'disabled';
$option[] = 'hidden';
}
$option['value'] ??= $value;
$label = $option['label'] ?? $option['value'];
unset($option['label']);
if (in_array($option['value'], $selected)) {
$option[] = 'selected';
} else {
if ($value === "none") {
$option[] = 'selected';
$option['value'] = ""; // Force User to select...
}
}
$html .= '<option'.$this->html->attributes($option).'>'.$this->html->escape($label).'</option>';

Loading…
Cancel
Save