From a2e7c0febecace0048bef6575cf25046cc387b3d Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Mon, 18 Jul 2011 20:33:45 -0400 Subject: [PATCH] Optimization in FormHelper::postLink(). --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 4 ++-- lib/Cake/View/Helper/FormHelper.php | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 30b95ab35c1..e3995f32af4 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -5666,7 +5666,7 @@ public function testPostLink() { $result = $this->Form->postLink('Delete', '/posts/delete/1'); $this->assertTags($result, array( 'form' => array( - 'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8', + 'method' => 'post', 'action' => '/posts/delete/1', 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;' ), 'div' => array('style' => 'display:none;'), @@ -5681,7 +5681,7 @@ public function testPostLink() { $result = $this->Form->postLink('Delete', '/posts/delete/1', array(), 'Confirm?'); $this->assertTags($result, array( 'form' => array( - 'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8', + 'method' => 'post', 'action' => '/posts/delete/1', 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;' ), 'div' => array('style' => 'display:none;'), diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 762171fc673..6c5c52024ea 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -335,8 +335,8 @@ public function create($model = null, $options = array()) { if ($model !== false) { $object = $this->_getModel($model); $key = $this->_introspectModel($model, 'key'); + $this->setEntity($model, true); } - $this->setEntity($model, true); if ($model !== false && $key) { $recordExists = ( @@ -419,7 +419,6 @@ public function create($model = null, $options = array()) { } $this->requestType = strtolower($options['type']); - $action = $this->url($options['action']); unset($options['type'], $options['action']); @@ -457,7 +456,9 @@ public function create($model = null, $options = array()) { $append = $this->Html->useTag('block', ' style="display:none;"', $append); } - $this->setEntity($model, true); + if ($model !== false) { + $this->setEntity($model, true); + } return $this->Html->useTag('form', $action, $htmlAttributes) . $append; } @@ -1504,14 +1505,16 @@ public function postLink($title, $url = null, $options = array(), $confirmMessag } $formName = uniqid('post_'); - $out = $this->create(false, array('url' => $url, 'name' => $formName, 'id' => $formName, 'style' => 'display:none;')); + $formUrl = $this->url($url); + $out = $this->Html->useTag('form', $formUrl, array('name' => $formName, 'id' => $formName, 'style' => 'display:none;', 'method' => 'post')); + $out .= $this->Html->useTag('block', ' style="display:none;"', $this->Html->useTag('hidden', '_method', ' value="POST"')); if (isset($options['data']) && is_array($options['data'])) { foreach ($options['data'] as $key => $value) { $out .= $this->hidden($key, array('value' => $value, 'id' => false)); } unset($options['data']); } - $out .= $this->end(); + $out .= $this->Html->useTag('formend'); $url = '#'; $onClick = 'document.' . $formName . '.submit();';