summaryrefslogtreecommitdiff
path: root/inc/form.php
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2010-06-15 10:08:38 +0200
committerAdrian Lang <lang@cosmocode.de>2010-06-15 11:26:52 +0200
commit2f10258ced4ab47311afffce07755551ac30e1df (patch)
treea40381ce3362e89665de2cd53f7e7d62d3c75704 /inc/form.php
parentb625808123f9b91b9803f98f818d5745bd7692cc (diff)
downloadrpg-2f10258ced4ab47311afffce07755551ac30e1df.tar.gz
rpg-2f10258ced4ab47311afffce07755551ac30e1df.tar.bz2
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.
Diffstat (limited to 'inc/form.php')
-rw-r--r--inc/form.php12
1 files changed, 11 insertions, 1 deletions
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 <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 />';