3 # Copyright 2018 Paul Hänsch
5 # This is the forms helper, part of CGIlite.
7 # CGIlite is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # CGIlite is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with CGIlite. If not, see <http://www.gnu.org/licenses/>.
20 # ksh and zsh workaround
21 # set -o posix # ksh, not portable
22 setopt -o OCTAL_ZEROES 2>&-
25 # Usage: form_radio Name Value Condition Label
26 # if "Condition" is the same as "Value", the button will be checked
32 id="rd_${name}_${value}"
34 [ "$value" = "$cond" ] && check='checked="checked"' || check=''
36 printf '<input type="radio" id="%s" name="%s" value="%s" %s /><label for="%s">%s</label>' \
37 "$id" "$name" "$value" "$check" "$id" "$label"
41 # Usage: form_check Name Value Condition Label
42 # if "Condition" is the same as "Value", the Checkbox will be checked
48 id="rd_${name}_${value}"
50 [ "$value" = "$cond" ] && check='checked="checked"' || check=''
52 printf '<input type="checkbox" id="%s" name="%s" value="%s" %s /><label for="%s">%s</label>' \
53 "$id" "$name" "$value" "$check" "$id" "$label"