Kaynağa Gözat

ZF-10529: Removed empty ID attributes from submit elements

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23402 44c647ce-9c0f-0410-b52a-842ac1e357ba
bittarman 15 yıl önce
ebeveyn
işleme
325595665e

+ 6 - 3
library/Zend/View/Helper/FormSubmit.php

@@ -56,14 +56,17 @@ class Zend_View_Helper_FormSubmit extends Zend_View_Helper_FormElement
     public function formSubmit($name, $value = null, $attribs = null)
     {
         $info = $this->_getInfo($name, $value, $attribs);
-        extract($info); // name, value, attribs, options, listsep, disable
-
+        extract($info); // name, value, attribs, options, listsep, disable, id
         // check if disabled
         $disabled = '';
         if ($disable) {
             $disabled = ' disabled="disabled"';
         }
 
+        if ($id) {
+            $id = ' id="' . $this->view->escape($id) . '"';
+        }
+
         // XHTML or HTML end tag?
         $endTag = ' />';
         if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
@@ -73,7 +76,7 @@ class Zend_View_Helper_FormSubmit extends Zend_View_Helper_FormElement
         // Render the button.
         $xhtml = '<input type="submit"'
                . ' name="' . $this->view->escape($name) . '"'
-               . ' id="' . $this->view->escape($id) . '"'
+               . $id
                . ' value="' . $this->view->escape($value) . '"'
                . $disabled
                . $this->_htmlAttribs($attribs)

+ 9 - 0
tests/Zend/View/Helper/FormSubmitTest.php

@@ -129,6 +129,15 @@ class Zend_View_Helper_FormSubmitTest extends PHPUnit_Framework_TestCase
         $test = $this->helper->formSubmit('foo', 'bar');
         $this->assertContains(' />', $test);
     }
+
+    /**
+     * @group ZF-10529
+     */
+    public function testDoesNotOutputEmptyId()
+    {
+        $test = $this->helper->formSubmit('', 'bar');
+        $this->assertNotContains('id=""', $test);
+    }
 }
 
 // Call Zend_View_Helper_FormSubmitTest::main() if this source file is executed directly.