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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

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