Skip to content

Commit

Permalink
correct target attribute for postLinks
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Dec 12, 2012
1 parent 1516434 commit ae7f629
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 13 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -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'
));
}

/**
Expand Down
12 changes: 9 additions & 3 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -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
));
Expand Down

0 comments on commit ae7f629

Please sign in to comment.