Browse Source

ZF-10791
Zend_Form
Zend_Form method setName() has no effect


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23945 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan 14 years ago
parent
commit
860e6b9875

+ 18 - 0
library/Zend/View/Helper/Doctype.php

@@ -189,6 +189,24 @@ class Zend_View_Helper_Doctype extends Zend_View_Helper_Abstract
     {
         return (stristr($this->getDoctype(), 'xhtml') ? true : false);
     }
+
+    /**
+     * Is doctype strict?
+     *
+     * @return boolean
+     */
+    public function isStrict()
+    {
+        switch ( $this->getDoctype() )
+        {
+            case self::XHTML1_STRICT:
+            case self::XHTML11:
+            case self::HTML4_STRICT:
+                return true;
+            default: 
+                return false;
+        }
+    }
     
     /**
      * Is doctype HTML5? (HeadMeta uses this for validation)

+ 11 - 0
library/Zend/View/Helper/Form.php

@@ -55,9 +55,20 @@ class Zend_View_Helper_Form extends Zend_View_Helper_FormElement
         if (array_key_exists('id', $attribs) && empty($attribs['id'])) {
             unset($attribs['id']);
         }
+        
+        if (!empty($name) && !($this->_isXhtml() && $this->_isStrictDoctype())) {
+            $name = ' name="' . $this->view->escape($name) . '"';
+        } else {
+            $name = '';
+        }
+        
+        if ( array_key_exists('name', $attribs) && empty($attribs['id'])) {
+            unset($attribs['id']);
+        }
 
         $xhtml = '<form'
                . $id
+               . $name
                . $this->_htmlAttribs($attribs)
                . '>';
 

+ 10 - 0
library/Zend/View/Helper/FormElement.php

@@ -146,6 +146,16 @@ abstract class Zend_View_Helper_FormElement extends Zend_View_Helper_HtmlElement
             $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']);
+        }
+        
+        // Override name in info if specified in attribs
+        if (array_key_exists('name', $attribs) && $attribs['name'] != $info['name']) {
+            $info['name'] = $attribs['name'];
+        }
 
         // Determine escaping from attributes
         if (array_key_exists('escape', $attribs)) {

+ 11 - 0
library/Zend/View/Helper/HtmlElement.php

@@ -76,6 +76,17 @@ abstract class Zend_View_Helper_HtmlElement extends Zend_View_Helper_Abstract
     }
 
     /**
+     * Is doctype strict?
+     *
+     * @return boolean
+     */
+    protected function _isStrictDoctype()
+    {
+        $doctype = $this->view->doctype();
+        return $doctype->isStrict();
+    }
+    
+    /**
      * Converts an associative array to a string of tag attributes.
      *
      * @access public