Browse Source

Merge pull request #6490 from cakephp/issue-6488

Allow creating form tag without "action" attribute.
Mark Story 11 years ago
parent
commit
bb9ff2519f
2 changed files with 31 additions and 3 deletions
  1. 8 3
      src/View/Helper/FormHelper.php
  2. 23 0
      tests/TestCase/View/Helper/FormHelperTest.php

+ 8 - 3
src/View/Helper/FormHelper.php

@@ -367,11 +367,16 @@ class FormHelper extends Helper
         }
         unset($options['templates']);
 
-        $url = $this->_formUrl($context, $options);
-        $action = $this->Url->build($url);
-        unset($options['url'], $options['action'], $options['idPrefix']);
+        if ($options['action'] === false || $options['url'] === false) {
+            $url = $this->request->here(false);
+            $action = null;
+        } else {
+            $url = $this->_formUrl($context, $options);
+            $action = $this->Url->build($url);
+        }
 
         $this->_lastAction($url);
+        unset($options['url'], $options['action'], $options['idPrefix']);
 
         $htmlAttributes = [];
         switch (strtolower($options['type'])) {

+ 23 - 0
tests/TestCase/View/Helper/FormHelperTest.php

@@ -674,6 +674,29 @@ class FormHelperTest extends TestCase
     }
 
     /**
+     * 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);
+
+        $result = $this->Form->create(false, ['action' => false]);
+        $this->assertHtml($expected, $result);
+    }
+
+    /**
      * test create() with a custom route
      *
      * @return void