From 616108d95f68d4d0c7dec334b262939782f355dc Mon Sep 17 00:00:00 2001 From: arno Date: Wed, 18 Aug 2010 21:45:49 +0200 Subject: [PATCH] do not add a hidden input before checkbox inputs --- application/forms/Geom.php | 1 + application/forms/User.php | 1 + application/views/helpers/SyjFormCheckbox.php | 56 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 application/views/helpers/SyjFormCheckbox.php diff --git a/application/forms/Geom.php b/application/forms/Geom.php index 61dde0c..3d99a87 100644 --- a/application/forms/Geom.php +++ b/application/forms/Geom.php @@ -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', diff --git a/application/forms/User.php b/application/forms/User.php index 288dec6..8fd2445 100644 --- a/application/forms/User.php +++ b/application/forms/User.php @@ -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 index 0000000..ae49370 --- /dev/null +++ b/application/views/helpers/SyjFormCheckbox.php @@ -0,0 +1,56 @@ +_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 .= '_htmlAttribs($attribs) + . $endTag; + + return $xhtml; + + } +} -- 2.39.2