Removing the extra elements on Zend_Form for Submit Button

This post is more than 18 months old. Since technology changes to rapidly, this content may be out of date (but that's not always the case). Please remember to verify any technical or programming information with the current release.

Have you ever used Zend Form, created a submit button, and had a few extra tags that were just throwing you off? I know you have… You probably did it like me:

$this->addElement('submit', 'submitbutton', array(
  'label'=>'Submit This',

But, you’ll notice you have both a dt and a dd from the standard view helpers of HtmlTag. But, the dt usually contains the label attribute. In this case, the label element is part of the input now. It stead of being silly and using CSS to hide that empty dt, let’s just get rid of it… add the following to your code:

$element = $this->getElement('submitbutton');
    array('HtmlTag', array('tag'=>'dd', 'id'=>$element->getName() . '-element'))

Simply, get the submit button you just added (you could technically add this in your definition of your initial element too…). Then, reset the decorators to be the ViewHelper and the HtmlTag. However, only define the dd tag instead of the full dd/dt suite. Finally, set the id to the element’s name plus -element like the standard view does.

Good to go!

Return to All Posts