X-Git-Url: http://git.plutz.net/?p=shcgi;a=blobdiff_plain;f=forms.sh;fp=forms.sh;h=50cb20431a15061370b879f8664d3d567a46fa6d;hp=0000000000000000000000000000000000000000;hb=72d6ccf5602d014bbdc991eb804ebcc236f1d0c5;hpb=cb80645196ee9d9a757434e33d2a2a1c48b0a2a3
diff --git a/forms.sh b/forms.sh
new file mode 100755
index 0000000..50cb204
--- /dev/null
+++ b/forms.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+# Copyright 2018 Paul Hänsch
+#
+# This is the forms helper, part of CGIlite.
+#
+# CGIlite is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# CGIlite is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with CGIlite. If not, see .
+
+# ksh and zsh workaround
+# set -o posix # ksh, not portable
+setopt -o OCTAL_ZEROES 2>&-
+
+form_radio(){
+ # Usage: form_radio Name Value Condition Label
+ # if "Condition" is the same as "Value", the button will be checked
+
+ name="$1"
+ value="$2"
+ cond="$3"
+ label="$4"
+ id="rd_${name}_${value}"
+
+ [ "$value" = "$cond" ] && check='checked="checked"' || check=''
+
+ printf '' \
+ "$id" "$name" "$value" "$check" "$id" "$label"
+}
+
+form_check(){
+ # Usage: form_check Name Value Condition Label
+ # if "Condition" is the same as "Value", the Checkbox will be checked
+
+ name="$1"
+ value="$2"
+ cond="$3"
+ label="$4"
+ id="rd_${name}_${value}"
+
+ [ "$value" = "$cond" ] && check='checked="checked"' || check=''
+
+ printf '' \
+ "$id" "$name" "$value" "$check" "$id" "$label"
+}