Permalink
Browse files

Optimization in FormHelper::postLink().

  • Loading branch information...
1 parent 222df2c commit a2e7c0febecace0048bef6575cf25046cc387b3d @jrbasso jrbasso committed Jul 19, 2011
Showing with 10 additions and 7 deletions.
  1. +2 −2 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +8 −5 lib/Cake/View/Helper/FormHelper.php
View
4 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;'),
View
13 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();';

0 comments on commit a2e7c0f

Please sign in to comment.