mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Merge pull request #1018 from dereuromark/2.3-postlink-target
Put target attr on correct element when using postLink()
This commit is contained in:
commit
408f9dd3b0
2 changed files with 22 additions and 3 deletions
|
@ -6321,6 +6321,19 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
$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'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1721,12 +1721,18 @@ class FormHelper extends AppHelper {
|
|||
|
||||
$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
|
||||
));
|
||||
|
|
Loading…
Add table
Reference in a new issue