From 58de6702bc02aa395997bdf51099adf7a9a1bafe Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 14 Nov 2012 21:27:12 -0500 Subject: [PATCH] Fix notice errors when creating fields named 0. Fixes #3371 --- .../Test/Case/View/Helper/FormHelperTest.php | 17 +++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 4549e48a0..118f62a40 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2153,6 +2153,23 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * Test that inputs with 0 can be created. + * + * @return void + */ + public function testInputZero() { + $this->Form->create('User'); + $result = $this->Form->input('0'); + $expected = array( + 'div' => array('class' => 'input text'), + 'label' => array('for' => 'User0'), '/label', + 'input' => array('type' => 'text', 'name' => 'data[User][0]', 'id' => 'User0'), + '/div' + ); + $this->assertTags($result, $expected); + } + /** * test input() with checkbox creation * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 34c344c3d..71eb1a788 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -199,7 +199,7 @@ class FormHelper extends AppHelper { $this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple'); } } - if (empty($field)) { + if ($field === null || $field === false) { return $this->fieldset[$model]['fields']; } elseif (isset($this->fieldset[$model]['fields'][$field])) { return $this->fieldset[$model]['fields'][$field]; @@ -773,7 +773,7 @@ class FormHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::label */ public function label($fieldName = null, $text = null, $options = array()) { - if (empty($fieldName)) { + if ($fieldName === null) { $fieldName = implode('.', $this->entity()); }