diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2023-01-20 20:22:06 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2023-01-20 20:22:06 +0100 |
commit | 277fedffc624f55c6ecc8bd80ed8db370134e47e (patch) | |
tree | ac22560f978c3789a63c80284fbd314e11d0b396 /includes/view-helpers/select-field-helper.php | |
parent | f499d9e657fe79e4413eec9e20ae13d616fac6f5 (diff) | |
download | gigologadmin-277fedffc624f55c6ecc8bd80ed8db370134e47e.tar.gz gigologadmin-277fedffc624f55c6ecc8bd80ed8db370134e47e.tar.bz2 gigologadmin-277fedffc624f55c6ecc8bd80ed8db370134e47e.zip |
Rename and reorganize more source files.
Diffstat (limited to 'includes/view-helpers/select-field-helper.php')
-rw-r--r-- | includes/view-helpers/select-field-helper.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/includes/view-helpers/select-field-helper.php b/includes/view-helpers/select-field-helper.php new file mode 100644 index 0000000..c25244b --- /dev/null +++ b/includes/view-helpers/select-field-helper.php @@ -0,0 +1,37 @@ +<?php +/** + * Select field implementation. + * + * @package giglogadmin + * + * SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com> + * SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net> + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace EternalTerror\ViewHelpers; + +/** + * Return HTML code for a selction box with the given options and preselected value. + * + * @param string $name The name attribute for the selection box + * @param array $opts The options as arrays of [value, label] pairs + * @param mixed|int $selected The value of the preselected option, or null if no + * option is preselected. + * @param string $blank Text to use for "no selection", defaults to "Please + * select..." + * @return string + */ +function select_field( + string $name, + array $opts = array(), + $selected = null, + string $blank = 'Please select...' ) : string { + $body = "<option value=\"\">{$blank}</option>"; + foreach ( $opts as $opt ) { + $sel = selected( $selected, $opt[0], false ); + $body .= "<option value=\"{$opt[0]}\"{$sel}>{$opt[1]}</option>"; + } + return "<select name=\"{$name}\">{$body}</select>"; +} |