From: paul Date: Wed, 21 Feb 2018 15:28:44 +0000 (+0000) Subject: helper for writing html forms X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=72d6ccf5602d014bbdc991eb804ebcc236f1d0c5;p=clickslide helper for writing html forms svn path=/trunk/; revision=60 --- 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" +}