diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 9cba3446c1d..70ec36cf924 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -8608,6 +8608,26 @@ public function testCreate() { } /** + * Test create() with no URL (no "action" attribute for
tag) + * + * @return void + */ + public function testCreateNoUrl() { + $result = $this->Form->create(false, array('url' => false)); + $expected = array( + 'form' => array( + 'id' => 'addForm', + 'method' => 'post', + 'accept-charset' => strtolower(Configure::read('App.encoding')) + ), + 'div' => array('style' => 'display:none;'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/div' + ); + $this->assertTags($result, $expected); + } + + /** * Test the onsubmit option for create() * * @return void diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 1f259a9418f..da064f30859 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -393,7 +393,7 @@ public function create($model = null, $options = array()) { if ($options['action'] === null && $options['url'] === null) { $options['action'] = $this->request->here(false); - } elseif (empty($options['url']) || is_array($options['url'])) { + } elseif (is_array($options['url'])) { if (empty($options['url']['controller'])) { if (!empty($model)) { $options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model)); @@ -421,7 +421,6 @@ public function create($model = null, $options = array()) { } elseif (is_string($options['url'])) { $options['action'] = $options['url']; } - unset($options['url']); switch (strtolower($options['type'])) { case 'get': @@ -442,7 +441,13 @@ public function create($model = null, $options = array()) { } $this->requestType = strtolower($options['type']); - $action = $this->url($options['action']); + if ($options['action'] === false || $options['url'] === false) { + $action = null; + } else { + $action = $this->url($options['action']); + } + unset($options['url']); + $this->_lastAction($options['action']); unset($options['type'], $options['action']); @@ -475,6 +480,10 @@ public function create($model = null, $options = array()) { $this->_introspectModel($model, 'fields'); } + if ($action === null) { + return $this->Html->useTag('formwithoutaction', $htmlAttributes) . $append; + } + return $this->Html->useTag('form', $action, $htmlAttributes) . $append; } diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 5098cec8670..2f260a68093 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -49,6 +49,7 @@ class HtmlHelper extends AppHelper { 'link' => '%s', 'mailto' => '%s', 'form' => '', + 'formwithoutaction' => '', 'formend' => '', 'input' => '', 'textarea' => '',