]> git.plutz.net Git - cgilite/blob - forms.sh
stub support for multiline comments (e.g. css/js embedding)
[cgilite] / forms.sh
1 #!/bin/sh
2
3 # Copyright 2018 Paul Hänsch
4 #
5 # This is the forms helper, part of CGIlite.
6
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.
11
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.
16
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/>. 
19
20 # ksh and zsh workaround
21 # set -o posix # ksh, not portable
22 setopt -o OCTAL_ZEROES 2>&-
23
24 form_radio(){
25   # Usage: form_radio Name Value Condition Label
26   # if "Condition" is the same as "Value", the button will be checked
27
28   name="$1"
29   value="$2"
30   cond="$3"
31   label="$4"
32   id="rd_${name}_${value}"
33
34   [ "$value" = "$cond" ] && check='checked="checked"' || check=''
35
36   printf '<input type="radio" id="%s" name="%s" value="%s" %s /><label for="%s">%s</label>' \
37          "$id" "$name" "$value" "$check" "$id" "$label"
38 }
39
40 form_check(){
41   # Usage: form_check Name Value Condition Label
42   # if "Condition" is the same as "Value", the Checkbox will be checked
43
44   name="$1"
45   value="$2"
46   cond="$3"
47   label="$4"
48   id="rd_${name}_${value}"
49
50   [ "$value" = "$cond" ] && check='checked="checked"' || check=''
51
52   printf '<input type="checkbox" id="%s" name="%s" value="%s" %s /><label for="%s">%s</label>' \
53          "$id" "$name" "$value" "$check" "$id" "$label"
54 }