diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 88422256e..570e57cc6 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -5836,6 +5836,35 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * Test that a checkbox can have 0 for the value and 1 for the hidden input. + * + * @return void + */ + public function testCheckboxZeroValue() { + $result = $this->Form->input('User.get_spam', array( + 'type' => 'checkbox', + 'value' => '0', + 'hiddenField' => '1', + )); + $expected = array( + 'div' => array('class' => 'input checkbox'), + array('input' => array( + 'type' => 'hidden', 'name' => 'data[User][get_spam]', + 'value' => '1', 'id' => 'UserGetSpam_' + )), + array('input' => array( + 'type' => 'checkbox', 'name' => 'data[User][get_spam]', + 'value' => '0', 'id' => 'UserGetSpam' + )), + 'label' => array('for' => 'UserGetSpam'), + 'Get Spam', + '/label', + '/div' + ); + $this->assertTags($result, $expected); + } + /** * testDateTime method * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 211cc84fc..32f1257be 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1402,14 +1402,11 @@ class FormHelper extends AppHelper { unset($options['default']); } - $options += array('required' => false); + $options += array('value' => 1, 'required' => false); $options = $this->_initInputField($fieldName, $options) + array('hiddenField' => true); $value = current($this->value($valueOptions)); $output = ''; - if (empty($options['value'])) { - $options['value'] = 1; - } if ( (!isset($options['checked']) && !empty($value) && $value == $options['value']) || !empty($options['checked'])