From 2f10258ced4ab47311afffce07755551ac30e1df Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 15 Jun 2010 10:08:38 +0200 Subject: =?UTF-8?q?Add=20an=20optional=20off=20value=20to=20Doku=5FForm?= =?UTF-8?q?=E2=80=99s=20checkboxes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since an unchecked HTML checkbox has no value at all, a hidden field may be used to specify an off value for the checkbox. --- inc/form.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/form.php b/inc/form.php index cebaf4608..70190d2b4 100644 --- a/inc/form.php +++ b/inc/form.php @@ -484,6 +484,8 @@ function form_makeFileField($name, $label=null, $id='', $class='', $attrs=array( * form_makeCheckboxField * * Create a form element for a checkbox input element with label. + * If $value is an array, a hidden field with the same name and the value + * $value[1] is constructed as well. * * @see form_makeFieldRight * @author Tom N Harris @@ -818,6 +820,8 @@ function form_filefield($attrs) { * _class : class attribute used on the label tag * _text : Text to display after the input. Not escaped. * Other attributes are passed to buildAttributes() for the input tag. + * If value is an array, a hidden field with the same name and the value + * $attrs['value'][1] is constructed as well. * * @author Tom N Harris */ @@ -827,7 +831,13 @@ function form_checkboxfield($attrs) { $s = ''; + $s .= '>'; + if (is_array($attrs['value'])) { + echo ''; + $attrs['value'] = $attrs['value'][0]; + } + $s .= ''; $s .= ' '.$attrs['_text'].''; if (preg_match('/(^| )block($| )/', $attrs['_class'])) $s .= '
'; -- cgit v1.2.3