Skip to content
Snippets Groups Projects
Commit 2f10258c authored by Adrian Lang's avatar Adrian Lang
Browse files

Add an optional off value to Doku_Form’s checkboxes

Since an unchecked HTML checkbox has no value at all, a hidden field may be
used to specify an off value for the checkbox.
parent b6258081
No related branches found
No related tags found
No related merge requests found
...@@ -484,6 +484,8 @@ function form_makeFileField($name, $label=null, $id='', $class='', $attrs=array( ...@@ -484,6 +484,8 @@ function form_makeFileField($name, $label=null, $id='', $class='', $attrs=array(
* form_makeCheckboxField * form_makeCheckboxField
* *
* Create a form element for a checkbox input element with label. * 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 * @see form_makeFieldRight
* @author Tom N Harris <tnharris@whoopdedo.org> * @author Tom N Harris <tnharris@whoopdedo.org>
...@@ -818,6 +820,8 @@ function form_filefield($attrs) { ...@@ -818,6 +820,8 @@ function form_filefield($attrs) {
* _class : class attribute used on the label tag * _class : class attribute used on the label tag
* _text : Text to display after the input. Not escaped. * _text : Text to display after the input. Not escaped.
* Other attributes are passed to buildAttributes() for the input tag. * 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> * @author Tom N Harris <tnharris@whoopdedo.org>
*/ */
...@@ -827,7 +831,13 @@ function form_checkboxfield($attrs) { ...@@ -827,7 +831,13 @@ function form_checkboxfield($attrs) {
$s = '<label'; $s = '<label';
if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"'; if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"'; 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>'; $s .= ' <span>'.$attrs['_text'].'</span></label>';
if (preg_match('/(^| )block($| )/', $attrs['_class'])) if (preg_match('/(^| )block($| )/', $attrs['_class']))
$s .= '<br />'; $s .= '<br />';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment