]> dev.renevier.net Git - syj.git/commitdiff
do not add a hidden input before checkbox inputs
authorarno <arno@renevier.net>
Wed, 18 Aug 2010 19:45:49 +0000 (21:45 +0200)
committerarno <arno@renevier.net>
Wed, 18 Aug 2010 19:45:49 +0000 (21:45 +0200)
application/forms/Geom.php
application/forms/User.php
application/views/helpers/SyjFormCheckbox.php [new file with mode: 0644]

index 61dde0ca1fb8af572470e0dce31ee20849eb2730..3d99a87bd6014b7522b2bee84c7bef81439be960 100644 (file)
@@ -27,6 +27,7 @@ class Syj_Form_Geom extends Zend_Form
         $text = $translator->translate("I've read and accepted %s");
         $text = vsprintf($text, $anchor);
         $touaccept = array('Checkbox', 'geom_accept', array("label" => $text,
+                            'helper' => 'SyjFormCheckbox', // similar to FormCheckbox without a hidden input
                             'decorators' => array(
                                   'ViewHelper',
                                   'label',
index 288dec6ee1d0644b906ef02eacd4dd32e1050f1f..8fd24458a5e3cdaa242940740d32b404b9f9da58 100644 (file)
@@ -46,6 +46,7 @@ class Syj_Form_User extends Syj_Form_TableAbstract
         $text = $translator->translate("I've read and accepted %s");
         $text = vsprintf($text, $anchor);
         $this->addElement('Checkbox', 'user_accept', array("label" => $text,
+                            'helper' => 'SyjFormCheckbox', // similar to FormCheckbox without a hidden input
                             'decorators' => array(
                                   'ViewHelper',
                                   'label',
diff --git a/application/views/helpers/SyjFormCheckbox.php b/application/views/helpers/SyjFormCheckbox.php
new file mode 100644 (file)
index 0000000..ae49370
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
+    and is published under the AGPL license. */
+
+require_once 'Zend/View/Helper/FormCheckbox.php';
+
+class Syj_View_Helper_SyjFormCheckbox extends Zend_View_Helper_FormCheckbox
+{
+    public function SyjFormCheckbox($name, $value = null, $attribs = null, array $checkedOptions = null)
+    {
+        $info = $this->_getInfo($name, $value, $attribs);
+        extract($info); // name, id, value, attribs, options, listsep, disable
+
+        $checked = false;
+        if (isset($attribs['checked']) && $attribs['checked']) {
+            $checked = true;
+            unset($attribs['checked']);
+        } elseif (isset($attribs['checked'])) {
+            $checked = false;
+            unset($attribs['checked']);
+        }
+
+        $checkedOptions = self::determineCheckboxInfo($value, $checked, $checkedOptions);
+
+        // is the element disabled?
+        $disabled = '';
+        if ($disable) {
+            $disabled = ' disabled="disabled"';
+        }
+
+        // XHTML or HTML end tag?
+        $endTag = ' />';
+        if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
+            $endTag= '>';
+        }
+
+        // build the element
+        $xhtml = '';
+        if (!$disable && !strstr($name, '[]')) {
+            //XXX: we have just copied Zend_View_Helper_FormCheckbox, and
+            // commented this line.
+//            $xhtml = $this->_hidden($name, $checkedOptions['uncheckedValue']);
+        }
+        $xhtml .= '<input type="checkbox"'
+                . ' name="' . $this->view->escape($name) . '"'
+                . ' id="' . $this->view->escape($id) . '"'
+                . ' value="' . $this->view->escape($checkedOptions['checkedValue']) . '"'
+                . $checkedOptions['checkedString']
+                . $disabled
+                . $this->_htmlAttribs($attribs)
+                . $endTag;
+
+        return $xhtml;
+
+    }
+}