diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index b0c0db5f324..97e15fe8fa5 100755 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -256,6 +256,10 @@ protected function _isRequiredField($validationRules) { * - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url' * you should leave 'action' undefined. * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')` + * - `templates` The templates you want to use for this form. Any templates will be merged on top of + * the already loaded templates. This option can either be a filename in App/Config that contains + * the templates you want to load, or an array of templates to use. You can use + * resetTemplates() to restore the original templates. * - `context` Additional options for the context class. For example the EntityContext accepts a 'table' * option that allows you to set the specific Table class the form should be based on. * - `idPrefix` Prefix for generated ID attributes. @@ -284,10 +288,17 @@ public function create($model = null, $options = []) { 'action' => null, 'url' => null, 'encoding' => strtolower(Configure::read('App.encoding')), - 'idPrefix' => null + 'templates' => null, + 'idPrefix' => null, ]; $this->_idPrefix = $options['idPrefix']; + + if (!empty($options['templates'])) { + $this->templates($options['templates']); + } + unset($options['templates']); + $action = $this->url($this->_formUrl($context, $options)); unset($options['url'], $options['action'], $options['idPrefix']); diff --git a/tests/TestCase/View/Helper/FormHelperTest.php b/tests/TestCase/View/Helper/FormHelperTest.php index b18f633f1da..6b0dd5aefa7 100755 --- a/tests/TestCase/View/Helper/FormHelperTest.php +++ b/tests/TestCase/View/Helper/FormHelperTest.php @@ -337,6 +337,28 @@ public function testCreateGet() { $this->assertTags($result, $expected); } +/** + * Test create() with the templates option. + * + * @return void + */ + public function testCreateTemplates() { + $result = $this->Form->create($this->article, [ + 'templates' => [ + 'formstart' => '
', + ] + ]); + $expected = [ + 'form' => [ + 'class' => 'form-horizontal', + 'method' => 'post', + 'action' => '/articles/add', + 'accept-charset' => 'utf-8' + ] + ]; + $this->assertTags($result, $expected); + } + /** * test the create() method *