Commit: b09f06f011085b72c78194e0e77ba67986bd1fba

Author: gwoo | Date: 2010-03-10 08:27:47 -0800
fixing #39 form->create bad output
diff --git a/libraries/lithium/template/helper/Form.php b/libraries/lithium/template/helper/Form.php index 41206b7..4ef5d91 100644 --- a/libraries/lithium/template/helper/Form.php +++ b/libraries/lithium/template/helper/Form.php @@ -45,7 +45,7 @@ class Form extends \lithium\template\Helper { 'error' => '<div{:options}>{:content}</div>', 'errors' => '{:content}', 'file' => '<input type="file" name="{:name}"{:options} />', - 'form' => '<form action="{:url}"{:options}>{:content}', + 'form' => '<form action="{:url}"{:options}>{:append}', 'form-end' => '</form>', 'hidden' => '<input type="hidden" name="{:name}"{:options} />', 'field' => '<div{:wrap}>{:label}{:input}{:error}</div>', @@ -194,13 +194,14 @@ class Form extends \lithium\template\Helper { $scope = $params['scope']; $options = $params['options']; $_binding = $params['binding']; - $content = null; + $append = null; if (!in_array(strtolower($scope['method']), array('get', 'post'))) { - $content = $self->hidden('_method', array( - 'name' => '_method', 'value' => strtoupper($scope['method']) + $append = $self->hidden('_method', array( + 'value' => strtoupper($scope['method']) )); } + if ($scope['type'] == 'file') { if (strtolower($scope['method']) == 'get') { $scope['method'] = 'post'; @@ -212,7 +213,7 @@ class Form extends \lithium\template\Helper { $options['method'] = strtoupper($scope['method']); return $self->invokeMethod('_render', array( - $method, $template, compact('url', 'content', 'options') + $method, $template, compact('url', 'options', 'append') )); }; return $this->_filter($method, $params, $filter); diff --git a/libraries/lithium/tests/cases/template/helper/FormTest.php b/libraries/lithium/tests/cases/template/helper/FormTest.php index 7c06771..43f3cda 100644 --- a/libraries/lithium/tests/cases/template/helper/FormTest.php +++ b/libraries/lithium/tests/cases/template/helper/FormTest.php @@ -94,16 +94,31 @@ class FormTest extends \lithium\test\Unit { */ public function testRestFormCreation() { $result = $this->form->create(null, array('action' => 'delete', 'method' => 'delete')); - $this->assertTags($result, array('form' => array( - 'action' => "{$this->base}posts/delete", 'method' => 'DELETE' - ))); + $this->assertTags($result, array( + 'form' => array( + 'action' => "{$this->base}posts/delete", 'method' => 'DELETE' + ), + 'input' => array( + 'type' => "hidden", + 'name' => '_method', + 'value' => 'DELETE' + ) + )); $result = $this->form->create(null, array('method' => 'put', 'type' => 'file')); - $this->assertTags($result, array('form' => array( - 'action' => "{$this->base}posts/add", - 'method' => 'PUT', - 'enctype' => 'multipart/form-data' - ))); + $this->assertTags($result, array( + 'form' => array( + 'action' => "{$this->base}posts/add", + 'method' => 'PUT', + 'enctype' => 'multipart/form-data' + ), + 'input' => array( + 'type' => "hidden", + 'name' => '_method', + 'value' => 'PUT' + ) + )); + } public function testFormCreationWithBinding() { @@ -117,6 +132,10 @@ class FormTest extends \lithium\test\Unit { ) )); $result = $this->form->create($record); + $this->assertTags($result, array('form' => array( + 'action' => "{$this->base}posts/add", + 'method' => 'POST', + ))); } public function testFormDataBinding() {