July 13, 2011

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

Question by Simpanoz

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 
       // $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.

Answer by Starx

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.

...

Please fill the form - I will response as fast as I can!