diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index bf55639e41c..583dc1981c8 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -1179,7 +1179,7 @@ protected function _getLabel($fieldName, $options) { $label = $options['label']; } - if ($label === false && isset($options['input'])) { + if ($label === false && $options['type'] === 'checkbox') { return $options['input']; } if ($label === false) { diff --git a/tests/TestCase/View/Helper/FormHelperTest.php b/tests/TestCase/View/Helper/FormHelperTest.php index 2b39b82ec3e..e591d5487bc 100644 --- a/tests/TestCase/View/Helper/FormHelperTest.php +++ b/tests/TestCase/View/Helper/FormHelperTest.php @@ -5169,6 +5169,22 @@ public function testInputDate() { $this->assertNotContains('value="2008" selected="selected"', $result); } +/** + * Test the label option being set to false. + * + * @return void + */ + public function testInputLabelFalse() { + $this->Form->create($this->article); + $result = $this->Form->input('title', ['label' => false]); + $expected = [ + 'div' => ['class' => 'input text required'], + 'input' => ['type' => 'text', 'required' => 'required', 'id' => 'title', 'name' => 'title'], + '/div' + ]; + $this->assertHtml($expected, $result); + } + /** * testInputDateMaxYear method * @@ -6231,6 +6247,15 @@ public function testInputsNotNested() { ]; $this->assertHtml($expected, $result); + $result = $this->Form->input('foo', ['type' => 'checkbox', 'label' => false]); + $expected = [ + 'div' => ['class' => 'input checkbox'], + ['input' => ['type' => 'hidden', 'name' => 'foo', 'value' => '0']], + ['input' => ['type' => 'checkbox', 'name' => 'foo', 'id' => 'foo', 'value' => '1']], + '/div' + ]; + $this->assertHtml($expected, $result); + $result = $this->Form->input('confirm', [ 'type' => 'radio', 'options' => ['Y' => 'Yes', 'N' => 'No']