Index: tests/Zend/View/Helper/FormTest.php =================================================================== --- tests/Zend/View/Helper/FormTest.php (revision 23530) +++ tests/Zend/View/Helper/FormTest.php (working copy) @@ -108,6 +108,33 @@ $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get', 'id' => null)); $this->assertNotRegexp('/]*(id="")/', $form); } + + /** + * @see ZF-10791 + */ + public function testPassingNameAsAttributeShouldRenderNameAttrib() + { + $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get', 'name' => 'SomeNameAttr')); + $this->assertRegexp('/]*(name="SomeNameAttr")/', $form); + } + + /** + * @see ZF-10791 + */ + public function testPassingNoNameAttributeShouldNotRenderNameAttrib() + { + $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get')); + $this->assertNotRegexp('/]*(name=".*")/', $form); + } + + /** + * @see ZF-10791 + */ + public function testPassingEmptyNameAttributeShouldNotRenderNameAttrib() + { + $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get', 'name' => NULL)); + $this->assertNotRegexp('/]*(name=".*")/', $form); + } } // Call Zend_View_Helper_FormTest::main() if this source file is executed directly. Index: library/Zend/View/Helper/FormElement.php =================================================================== --- library/Zend/View/Helper/FormElement.php (revision 23530) +++ library/Zend/View/Helper/FormElement.php (working copy) @@ -146,6 +146,11 @@ $info['id'] = trim(strtr($info['name'], array('[' => '-', ']' => '')), '-'); } + + // Remove NULL name attribute override + if ( array_key_exists('name', $attribs) && is_null($attribs['name']) ) { + unset($attribs['name']); + } // Determine escaping from attributes if (array_key_exists('escape', $attribs)) { @@ -160,7 +165,8 @@ // Remove attribs that might overwrite the other keys. We do this LAST // because we needed the other attribs values earlier. foreach ($info as $key => $val) { - if (array_key_exists($key, $attribs)) { + // Allow override of name attribute + if ($key !== 'name' && array_key_exists($key, $attribs)) { unset($attribs[$key]); } }