diff --git a/inc/form.php b/inc/form.php index cebaf4608e8cbd5eeb45fcb44b1a20038e79d60d..70190d2b49b0dc2dceeab3cc18db93281260ab01 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 <tnharris@whoopdedo.org> @@ -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 <tnharris@whoopdedo.org> */ @@ -827,7 +831,13 @@ function form_checkboxfield($attrs) { $s = '<label'; if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"'; if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"'; - $s .= '><input type="checkbox" '.buildAttributes($attrs,true).'/>'; + $s .= '>'; + if (is_array($attrs['value'])) { + echo '<input type="hidden" name="' . hsc($attrs['name']) .'"' + . ' value="' . hsc($attrs['value'][1]) . '" />'; + $attrs['value'] = $attrs['value'][0]; + } + $s .= '<input type="checkbox" '.buildAttributes($attrs,true).'/>'; $s .= ' <span>'.$attrs['_text'].'</span></label>'; if (preg_match('/(^| )block($| )/', $attrs['_class'])) $s .= '<br />';