From 72d6ccf5602d014bbdc991eb804ebcc236f1d0c5 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 21 Feb 2018 15:28:44 +0000 Subject: [PATCH] helper for writing html forms svn path=/trunk/; revision=60 --- forms.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 forms.sh 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" +} -- 2.39.2