--- /dev/null
+#!/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 <http://www.gnu.org/licenses/>.
+
+# 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 '<input type="radio" id="%s" name="%s" value="%s" %s /><label for="%s">%s</label>' \
+ "$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 '<input type="checkbox" id="%s" name="%s" value="%s" %s /><label for="%s">%s</label>' \
+ "$id" "$name" "$value" "$check" "$id" "$label"
+}