Permalink
Browse files

Merge pull request #5931 from ThaDafinser/patch-6

Disable <label> for input hidden

Conflicts:
	library/Zend/Form/View/Helper/FormRow.php
  • Loading branch information...
2 parents 08d264c + 0865d2b commit 90e4176852197c49eef3cd47ac0af2440ffc3f29 @weierophinney weierophinney committed Mar 7, 2014
Showing with 11 additions and 2 deletions.
  1. +3 −2 library/Zend/Form/View/Helper/FormRow.php
  2. +8 −0 tests/ZendTest/Form/View/Helper/FormRowTest.php
@@ -160,7 +160,9 @@ public function render(ElementInterface $element)
$elementString = $elementHelper->render($element);
- if (isset($label) && '' !== $label) {
+ // hidden elements do not need a <label> -https://github.com/zendframework/zf2/issues/5607
+ $type = $element->getAttribute('type');
+ if (isset($label) && '' !== $label && $type !== 'hidden') {
$labelAttributes = array();
@@ -178,7 +180,6 @@ public function render(ElementInterface $element)
// Multicheckbox elements have to be handled differently as the HTML standard does not allow nested
// labels. The semantic way is to group them inside a fieldset
- $type = $element->getAttribute('type');
if ($type === 'multi_checkbox'
|| $type === 'radio'
|| $element instanceof MonthSelect
@@ -82,6 +82,14 @@ public function testCanCreateMarkupWithoutLabel()
$this->assertRegexp('/<input name="foo" type="text"[^\/>]*\/?>/', $markup);
}
+ public function testIgnoreLabelForHidden()
+ {
+ $element = new Element\Hidden('foo');
+ $element->setLabel('My label');
+ $markup = $this->helper->render($element);
+ $this->assertEquals('<input type="hidden" name="foo" value=""/>', $markup);
+ }
+
public function testCanHandleMultiCheckboxesCorrectly()
{
$options = array(

0 comments on commit 90e4176

Please sign in to comment.