Browse files

correct target attribute for postLinks

  • Loading branch information...
1 parent 1516434 commit ae7f629eff76d83edd74e49b80c7925f949fdd8b @dereuromark dereuromark committed Dec 12, 2012
Showing with 22 additions and 3 deletions.
  1. +13 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +9 −3 lib/Cake/View/Helper/FormHelper.php
View
13 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -6317,6 +6317,19 @@ public function testPostLink() {
$result = $this->Form->postLink('Delete', '/posts/delete', array('data' => array('id' => 1)));
$this->assertContains('<input type="hidden" name="data[id]" value="1"/>', $result);
+
+ $result = $this->Form->postLink('Delete', '/posts/delete/1', array('target' => '_blank'));
+ $this->assertTags($result, array(
+ 'form' => array(
+ 'method' => 'post', 'target' => '_blank', 'action' => '/posts/delete/1',
+ 'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
+ ),
+ 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
+ '/form',
+ 'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
+ 'Delete',
+ '/a'
+ ));
}
/**
View
12 lib/Cake/View/Helper/FormHelper.php
@@ -1720,12 +1720,18 @@ public function postLink($title, $url = null, $options = array(), $confirmMessag
$formName = uniqid('post_');
$formUrl = $this->url($url);
- $out = $this->Html->useTag('form', $formUrl, array(
+ $formOptions = array(
'name' => $formName,
'id' => $formName,
'style' => 'display:none;',
- 'method' => 'post'
- ));
+ 'method' => 'post',
+ );
+ if (isset($options['target'])) {
+ $formOptions['target'] = $options['target'];
+ unset($options['target']);
+ }
+
+ $out = $this->Html->useTag('form', $formUrl, $formOptions);
$out .= $this->Html->useTag('hidden', '_method', array(
'value' => $requestMethod
));

0 comments on commit ae7f629

Please sign in to comment.