diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index ddd1f9fd932..c4989159d48 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -4097,6 +4097,27 @@ public function testRadioLabelArray() { ); } +/** + * Test that label id's match the input element id's when radio is called after create(). + * + * @return void + */ + public function testRadioWithCreate() { + $this->Form->create('Model'); + $result = $this->Form->radio('recipient', + array('1' => '1', '2' => '2', '3' => '3'), + array('legend' => false, 'value' => '1') + ); + $this->assertTextNotContains( + '', + $result + ); + $this->assertTextContains( + '', + $result + ); + } + /** * testSelect method * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index d6583ac63ba..6cb89296116 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1520,7 +1520,9 @@ public function radio($fieldName, $options = array(), $attributes = array()) { ); if ($label) { - $optTitle = $this->label($tagName, $optTitle, is_array($label) ? $label : null); + $labelOpts = is_array($label) ? $label : array(); + $labelOpts += array('for' => $tagName); + $optTitle = $this->label($tagName, $optTitle, $labelOpts); } if (is_array($between)) {