Skip to content

Commit

Permalink
Allow creating form tag without "action" attribute.
Browse files Browse the repository at this point in the history
Closes #6488
  • Loading branch information
ADmad committed May 5, 2015
1 parent d6c54d8 commit 911aafa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/View/Helper/FormHelper.php
Expand Up @@ -367,11 +367,16 @@ public function create($model = null, array $options = [])
}
unset($options['templates']);

$url = $this->_formUrl($context, $options);
$action = $this->Url->build($url);
unset($options['url'], $options['action'], $options['idPrefix']);
if ($options['url'] === false) {
$action = null;
$this->_lastAction = '';
} else {
$url = $this->_formUrl($context, $options);
$action = $this->Url->build($url);

$this->_lastAction($url);
$this->_lastAction($url);
}
unset($options['url'], $options['action'], $options['idPrefix']);

$htmlAttributes = [];
switch (strtolower($options['type'])) {
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -673,6 +673,26 @@ public function testCreateAutoUrl()
$this->assertHtml($expected, $result);
}

/**
* test create() with no url (no "action" attribute for <form> tag)
*
* @return void
*/
public function testCreateNoUrl()
{
$result = $this->Form->create(false, ['url' => false]);
$expected = [
'form' => [
'method' => 'post',
'accept-charset' => strtolower(Configure::read('App.encoding'))
],
'div' => ['style' => 'display:none;'],
'input' => ['type' => 'hidden', 'name' => '_method', 'value' => 'POST'],
'/div'
];
$this->assertHtml($expected, $result);
}

/**
* test create() with a custom route
*
Expand Down

0 comments on commit 911aafa

Please sign in to comment.