开发者

Zend Framework: Zend_Form is not including 'name' attribute in form tag

开发者 https://www.devze.com 2023-03-19 18:34 出处:网络
I have following class for a form: class Application_Form_ContactForm extends Zend_Form { public function init()

I have following class for a form:

class Application_Form_ContactForm extends Zend_Form
{
    public function init()
    {
      $this->setName('contact_us');
     /* 
       I have also used follwing statements (one by one) to set name attribute开发者_如何学Go 
       // $this->setAttrib('name', 'myForm-name');
       // $this->setAttribs(array('name' => 'frm', 'id' => 'frmlogin')); 
     */
    }
}

When I run this form, I get follwoing html code:

<form id="contact_us" enctype="application/x-www-form-urlencoded" action="" method="post"><dl class="zend_form">

The above mentioned html code doesn't show 'name' attribute of the form html tag.

Can some one guide me in this regards, how to rectify it.


The "name" attribute is allowed in HTML4 but has been deprecated in XHTML1.0. The HTML specification does not allow for a "name" attribute for forms. Check Here and here.

Zend Framework is just following the rules.

But why do you need a name is form anyway? Almost everything can be done using class and id.

But, if you really need it that bad try setting a ID first and then the name, it might work.


I am trying to set focus for a text input of a form field. Without specifying the 'name' attribute, the OnLoad focus does NOT work. If 'name' is deprecated, there must be another way to support this focus(). A simple example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <title>Test</title>
    </head>
    <body OnLoad="document.InputForm.CMD.focus();">
       <div><b>Focus Test</b></div>
       <form ID="InputForm" method="post" action="">
           <input type="text" name="CMD" id="CMD" value="" size="50" />
           <input type="submit" name="OK" id="OK" value="OK" />
       </form>
</body>
</html>
0

精彩评论

暂无评论...
验证码 换一张
取 消