diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index b62092ed466..5c4435f9701 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1960,7 +1960,7 @@ function _name($options = array(), $field = null, $key = 'name') { } $view = ClassRegistry::getObject('view'); - $name = $view->field; + $name = !empty($view->field) ? $view->field : $view->model; if (!empty($view->fieldSuffix)) { $name .= '[' . $view->fieldSuffix . ']'; } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 3c4cea94029..ba979092f55 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -5729,6 +5729,28 @@ function testGetFormCreate() { ))); } +/** + * test get form, and inputs when the model param is false + * + * @return void + */ + function testGetFormWithFalseModel() { + $encoding = strtolower(Configure::read('App.encoding')); + $result = $this->Form->create(false, array('type' => 'get')); + + $expected = array('form' => array( + 'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add', + 'accept-charset' => $encoding + )); + $this->assertTags($result, $expected); + + $result = $this->Form->text('reason'); + $expected = array( + 'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason') + ); + $this->assertTags($result, $expected); + } + /** * test that datetime() works with GET style forms. *